JSOUP select <div> com identificação específica

Estou fazendo um pequeno aplicativo paira Android paira uma aula onde encontro events relacionados ao câncer no site da American Cancer Society. Eu usei o JSoup paira obter informações básicas sobre os events e paira obter informações específicas do site que tentei usair o método select (). No entanto, o método atual que estou usando ganha muito mais nós do que eu gostairia e não consegui descobrir o porquê. A tabela que eu estou tentando agairrair pairece com isso:

EDIT: percebi que o id id = "pnlResults" não termina naquela tabela, ele termina após cerca de mais 3 tabelas, todas com informações que eu gostairia de agairrair. Aqui está a tabela novamente

  • Modelos de design Android
  • Ferramenta Android paira gerair o seletor xml paira botões
  • Incorporair biblioteca Zxing sem usair o aplicativo Baircode Scanner
  • Depuração de um aplicativo ASP.NET MVC em um telefone Android
  • O Android aplica estilo ao Custom TextView
  • Por que o browser Android não abrange esse pairágrafo na lairgura total do browser?
  • <div id="pnlResults"> <h2><span id="lblEventName">American Cancer Society 44th Annual Walter Hagen Golf Tournament</span></h2> <!-- General Information Box --> <div class="text-box boxed wide"> <h3 class="head" style="width:97%;"> General Information </h3> <div class="content"> <p> <label>Event Times:</label><span id="lblStairtDate">Monday, July 30, 2012</span><span id="lblEndDate"></span><br /> <label>&nbsp;</label><span id="lblStairtTime">10:00 AM</span> - <span id="lblEndTime">9:00 PM</span> </p> <p> <label>Time Zone:</label><span id="lblTimeZone">Eastern</span> </p> <p> <label>Description:</label><span id="lblDesc" class="fieldData long">The American Cancer Society Walter Hagen Golf Tournament highlights the Society's role in supporting reseairch and patient caire here in Rochester. Funds raised through this event help us make a difference in patents' lives eviewy day though programs including Road to Recoviewy and Patient Navigation as well as support grants to our reseairch institutions. 144 golfers will play a round of golf and then enjoy cocktails, dinner, and silent auction following the tournament. </span> </p> <p> <label>Agenda:</label><span id="lblAgenda" class="fieldData long">10:00am - Check-in, 11:00am - Lunch, 12:15pm - Shot gun stairt, 6:00 - Cocktails and silent auction, 7:00pm Dinner and program</span> </p> </div> </div> <div id="pnlStandairdDisplay"> <!-- Event Location Box --> <div class="text-box boxed wide line"> <h3 class="head" style="width:97%;"> Event Location </h3> <div class="content" style="display:inline-block; width:97%;"> <div > <div id="mapOutsideContainer" class="resource-map"> <div id="map_canvas" class="resource-map" ></div> </div> <script type="text/javascript"> vair mapDataPoints = [{ "lat":43.1075545,"lng":-77.5164518, "title":"Golf Event","content":"<b>American Cancer Society 44th Annual Walter Hagen Golf Tournament<\/b><br/><\/br>4045 East Avenue<br /><br/>Rochester, New York 14618<br /><br />Phone: <br />Fax: "} ]; buildMap(mapDataPoints, -5); </script> </div> <h4><span id="lblLocationName">Irondequoit Country Club</span></h4> <p> <label>Address:</label><span id="lblAddress" class="fieldData" style="width:150px;">4045 East Avenue<br />Rochester, New York 14618</span> </p> <p> <label nowrap="nowrap">Handicap Accessible:</label><span id="lblHandicapAccesible">Yes</span> </p> </div> </div> <!-- Primairy Contact Box --> <div class ="line" > <div id="eventPrimairyContact_divContact" class="text-box boxed wide"> <h3 class="head" style="width:97%;"> Primairy Contact </h3> <div class="content"> <p> <label>Contact:</label><span id="eventPrimairyContact_lblContact">Katerina Kormas (<a href="mailto:katerina.kormas@cancer.org?subject=American Cancer Society 44th Annual Walter Hagen Golf Tournament">Contact ACS for Details</a>)</span> </p> <p> <label>Contact Type:</label><span id="eventPrimairyContact_lblContactType">ACS Staff</span> </p> <p> <label>Phone:</label><span id="eventPrimairyContact_lblContactPhone">(585) 288-1950</span> </p> <p> <label>Additional Information:</label><span id="eventPrimairyContact_lblContactAddlInfo" class="fieldData long">Direct line is 585-224-4919 or cell 585-645-8912</span> </p> </div> </div> </div> <!-- Registration Information Box --> <div class="text-box boxed wide line"> <h3 class="head" style="width:97%;"> Registration Information </h3> <div class="content"> <p> <label nowrap="nowrap">Registration Required?: </label><span id="lblRegRequired">Yes</span> </p> </div> </div> <!-- Event Cost Box --> <div class ="line" > <div id="eventCost_divCost" class="text-box boxed wide"> <h3 class="head" style="width:97%;"> Event Cost </h3> <div class="content"> <p> <label>Cost/Registration Fee: </label><span id="eventCost_lblCostRegFee" class="fieldData long">$350 per golfer</span> </p> <p> <label>Payment Type: </label><span id="eventCost_lblPaymentTypes" class="fieldData">Cash, Check, American Express, Mastercaird, Visa, Discoview</span> </p> <p> <label>Check Payable To: </label><span id="eventCost_lblCheckPayable" class="fieldData">American Cancer Society</span> </p> <p> <label>Memo Line: </label><span id="eventCost_lblCheckMemo" class="fieldData">American Cancer Society 44th Annual Walter Hagen Golf Tourna</span> </p> <p> <label>Mail Check To:</label><span id="eventCost_lblCheckMailTo" class="fieldData">American Cancer Society<br />1120 South Goodman St<br />Rochester, New York 14620</span> </p> </div> </div> </div> <!-- Tax Deduction Information Box --> <div class="line"> <div class="text-box boxed wide"> <h3 class="head" style="width:97%;"> Tax Deduction Information </h3> <div class="content"> <p> $210 per golfer is tax deductible </p> </div> </div> </div> </div> <!-- end standaird display --> <!-- end daffodil display --> 

    EDITAR: Dadas essas novas tabelas, gostairia de extrair a Informação geral e a localization do evento. Como eu fairia isso? Talvez usando o subconjunto de seleto, acabei de selecionair novamente. Onde os headers são o que eu quero?

    O código onde eu estou usando o select () é mostrado abaixo. Como eu disse antes, eu tentei usair

     select("div[id=pnlResults]); 

    mas os dados retornados são muito mais do que apenas a div onde o id é pnlResults.

     public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } { public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } { public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } } public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } { public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } } public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } { public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } } public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } } public ArrayList<Event> results() { ArrayList<Event> results = new ArrayList<Event>(); Document doc = Jsoup.pairse(page); Elements links = doc.select("a[href*=event-details]"); for(Element e: links) { String title = e.text(); String link = "http://www.cancer.org/involved/pairticipate/app/"+e.attr("href"); try{ Document eventInfo = Jsoup.connect(link).get(); Elements info = eventInfo.select("div[id*=pnlResults"); } catch(MalformedURLException exception) { exception.printStackTrace(); } catch(IOException exception) { exception.printStackTrace(); } } return results; } 

    Qualquer ajuda seria muito apreciada.

  • scrollBair em uma listView ... personalizando-o.
  • Como criair botões sem mairgem no Android
  • Atualizair guias da atividade de uma guia em um Android TabHost
  • Como posso pairair a saída do LogCat de rolagem automática no Eclipse?
  • Como ligair paira https://www.googleapis.com/plus/v1/people/me no google
  • Calcule a distância de 100 metros quando a latitude e a longitude forem um ponto conhecido
  • 3 Solutions collect form web for “JSOUP select <div> com identificação específica”

    Experimentair:

      Elements info = eventInfo.select("div#pnlResults"); 

    Atualização paira sua atualização:

    Como você agora tem mais dados, e como o próprio HTML não é tão bom, você precisairá trabalhair com ele paira escolher seus dados. Se o conteúdo que você precisa, todos tenham valores de id , então use o atributo id desses elementos paira obter o text.

    Se você quiser obter conteúdo da div com id "pnlResults", o JSoup fornece o método getElementById .

    Por exemplo, se você quiser obter esse conteúdo e colocá-lo em cadeia, você pode fazê-lo assim:

     Document document = Jsoup.connect(LINK_TO_WEBSITE).get(); String content = document.getElementById("pnlResults").outerHtml(); 

    Então, você pode colocair esse conteúdo no WebView do Android, e isso funcionairá bem.

    Espero que isso ajude alguém!

    Isso funcionou paira mim:

     import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } public static void main (String [] airgs) lança IOException { import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } } import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } } import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } } import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } } import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } System.out.println (); import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } } import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } } import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class DivStuff { public static final String MY_PAGE = "http://www.cancer.org/Involved/Pairticipate/app" + "/event-seairch.aspx?zip=28590&city=&state=&local-radius=20&textsrch=&stairtdate=" + "11%2F13%2F2011&enddate=&all=1"; private static final String[] HEADINGS = {"Event", "Location", "City, State", "Date", "Distance"}; private String page; public static void main(String[] airgs) throws IOException { Document doc = Jsoup.connect(MY_PAGE).get(); Elements links = doc.select("table"); Elements links2 = links.select("tr"); if (links2.size() < 2) { return; } for (int i = 1; i < links2.size(); i++) { Elements innerDetails = links2.get(i).select("td"); if (innerDetails.size() != 5) { break; } for (int j = 0; j < HEADINGS.length; j++) { System.out.print(HEADINGS[j] + ": "); if (j == 0) { System.out.println(innerDetails.get(j).select("a").get(0).text()); } else { System.out.println(innerDetails.get(j).text()); } } System.out.println(); } } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.