java - JSOUP extract an absolute URL in Android -


i've been looking everywhere. tried lot of "solutions" none of 'em helped. need extract url address of sub-website html code. code contains lot of url's need shorten result list somehow leaves links need.

details:

 <li class="container results-list-item clear-me ">             <div class="job-offer-content container h-card">                 <div class="position-head container">                   <div class="container  ">                       <h2 class="p-job-title">                           <a href="/praca/android-developer-junior-senior/wroclaw/11636002" rel="nofollow"                            title="praca android developer (junior/senior) dolnośląskie" class="job-offer ">                               <strong class="keyword">android</strong> <strong class="keyword">developer</strong> (junior/senior)                           </a>                       </h2>                           <h3 class="p-name company">                                   <a href="/pracodawca/starware-firma-informatyczna-praca/843242">                                       starware firma informatyczna                               </a>                           </h3> 

it part of html code. said, contains lot of url ideas doc.select("a").first(); not help.

i want extract url section <h2 class="p-job-title"> (it happens multiple times in code, because result of search on website) tried doc.select("h2.p-job-title a[href]"); output android developer (junior/senior) , need /pracodawca/starware-firma-informatyczna-praca/843242 , in absolute form @ best )i think www.mywebsite + url made concat or shouldn't hard).

edit: whole activity class' code

public class listaactivity extends actionbaractivity{     startactivity startactiv;     private list<string> mlista = new arraylist<>();     private listview mlistview;     private miastalistadapter madapter;     public elements jobname, jobname2;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_lista_miast);           mlistview = (listview) findviewbyid(r.id.lista_miast);           new newthread().execute();         madapter = new miastalistadapter(this, mlista);         mlistview.setadapter(madapter);     }      public class newthread extends asynctask<string, void, string> {         @override         protected string doinbackground(string... arg) {             string dourlwork = startactiv.nazwastanowiska;             string dourlplace = startactiv.nazwamiejscowosci;              document doc;             try {                 doc = (document) jsoup.connect("http://www.infopraca.pl/praca?q=" + dourlwork + "&lc=" + dourlplace)                         .useragent("mozilla/5.0 (windows nt 6.1; wow64; rv:5.0) gecko/20100101 firefox/5.0").get();                  jobname = doc.select("h2.p-job-title a[href]"); //infopraca                      (element jobnames : jobname) {                         mlista.add(jobnames.text() + "\n");                     }              } catch (ioexception e) {                 e.printstacktrace();             }             return null;         }          @override         protected void onpostexecute(string result) {             madapter.notifydatasetchanged();         }     } } 

you trying text selected elements. mlista.add(jobnames.text() + "\n"); wrong. if need links have attribute href selected elements.

try this

elements class= doc.getelementsbyclass("p-job-title"); elements link= class.select("a"); string url = link.attr("href"); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -