[HtmlUnit] [htmlunit:bugs] #2013 xpath returning more content than belongs in HtmlDivision
RBRi via HtmlUnit-develop <[email protected]> Sat, 30 Mar 2019 17:45:38 -0000
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | </p/htmlunit/bugs/2013/64d944fc608c1182d37301c38f31aed523971a29.bugs@htmlunit.p.sourceforge.net> |
This is a multi-part message in MIME format.
--===============6430589295408891477==
Content-Type: multipart/related;
boundary="===============7552512670075209791=="
This is a multi-part message in MIME format.
--===============7552512670075209791==
Content-Type: multipart/alternative;
boundary="===============8775400093531972733=="
MIME-Version: 1.0
--===============8775400093531972733==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Your second XPath is wrong:
// addresses all subnodes of the document node use .// instead
List<HtmlAnchor> zipcodeLinks = zipCodesDiv.getByXPath(".//li/a[contains(@href,'propertyrecord-search/')]");
---
** [bugs:#2013] xpath returning more content than belongs in HtmlDivision**
**Status:** open
**Group:** 2.34.1
**Created:** Sat Mar 30, 2019 05:21 PM UTC by arya
**Last Updated:** Sat Mar 30, 2019 05:21 PM UTC
**Owner:** nobody
I'm getting unussual results
I have the following HTMLUnit script which is supposed to extract the zipcode hrefs.
~~~
WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(false);
HtmlPage countyPage = webClient.getPage("https://www.realtor.com/propertyrecord-search/Autauga-County_AL");
HtmlDivision zipCodesDiv = (HtmlDivision) countyPage
.getByXPath("//h3[contains(., \"Zip Codes\")]/following::div[1]").get(0);
System.out.println(zipCodesDiv.asXml());
List<HtmlAnchor> zipcodeLinks = zipCodesDiv.getByXPath("//li/a[contains(@href,'propertyrecord-search/')]");
System.out.println("Zipcode link size: " + zipcodeLinks.size());
for (int zipcodeCount = 0; zipcodeCount < zipcodeLinks.size(); zipcodeCount++) {
System.out.println(zipcodeLinks.get(zipcodeCount));
}
~~~
zipCodesDiv contains the div that contains the zipcodes, however
zipCodesDiv.getByXPath("//li/a[contains(@href,'propertyrecord-search/')]");
is returning more content than it belongs in zipCodesDiv, it's also returning cities in Autauga County. Why is this happening? Is this a bug?
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
--===============8775400093531972733==
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit
<div class="markdown_content"><p>Your second XPath is wrong:</p>
<p>// addresses all subnodes of the document node use .// instead</p>
<div class="codehilite"><pre><span></span> List<HtmlAnchor> zipcodeLinks = zipCodesDiv.getByXPath(".//li/a[contains(@href,'propertyrecord-search/')]");
</pre></div>
<hr/>
<p><strong> <a class="alink" href="https://sourceforge.net/p/htmlunit/bugs/2013/">[bugs:#2013]</a> xpath returning more content than belongs in HtmlDivision</strong></p>
<p><strong>Status:</strong> open<br/>
<strong>Group:</strong> 2.34.1<br/>
<strong>Created:</strong> Sat Mar 30, 2019 05:21 PM UTC by arya<br/>
<strong>Last Updated:</strong> Sat Mar 30, 2019 05:21 PM UTC<br/>
<strong>Owner:</strong> nobody</p>
<p>I'm getting unussual results</p>
<p>I have the following HTMLUnit script which is supposed to extract the zipcode hrefs.</p>
<div class="codehilite"><pre><span></span><span class="nt">WebClient</span> <span class="nt">webClient</span> <span class="o">=</span> <span class="nt">new</span> <span class="nt">WebClient</span><span class="o">();</span>
<span class="nt">webClient</span><span class="p">.</span><span class="nc">getOptions</span><span class="o">()</span><span class="p">.</span><span class="nc">setJavaScriptEnabled</span><span class="o">(</span><span class="nt">false</span><span class="o">);</span>
<span class="nt">HtmlPage</span> <span class="nt">countyPage</span> <span class="o">=</span> <span class="nt">webClient</span><span class="p">.</span><span class="nc">getPage</span><span class="o">(</span><span class="s2">"https://www.realtor.com/propertyrecord-search/Autauga-County_AL"</span><span class="o">);</span>
<span class="nt">HtmlDivision</span> <span class="nt">zipCodesDiv</span> <span class="o">=</span> <span class="o">(</span><span class="nt">HtmlDivision</span><span class="o">)</span> <span class="nt">countyPage</span>
<span class="p">.</span><span class="nc">getByXPath</span><span class="o">(</span><span class="err">"</span><span class="o">//</span><span class="nt">h3</span><span class="cp">[</span><span class="nx">contains</span><span class="p">(</span><span class="nx">.</span><span class="p">,</span> <span class="o">\</span><span class="s2">"Zip Codes</span><span class="se">\"</span><span class="s2">)]/following::div[1]"</span><span class="p">)</span><span class="bp">.</span><span class="nb">get</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="nx">System.out.println</span><span class="p">(</span><span class="nx">zipCodesDiv.asXml</span><span class="p">());</span>
<span class="kt">List</span><span class="o"><</span><span class="nx">HtmlAnchor</span><span class="o">></span> <span class="n">zipcodeLinks</span><span class="o"> =</span> <span class="nx">zipCodesDiv.getByXPath</span><span class="p">(</span><span class="s2">"//li/a[contains(@href,'propertyrecord-search/')]"</span><span class="p">);</span>
<span class="nx">System.out.println</span><span class="p">(</span><span class="s2">"Zipcode link size: "</span> <span class="o">+</span> <span class="nx">zipcodeLinks.size</span><span class="p">());</span>
<span class="nx">for</span> <span class="p">(</span><span class="nx">int</span> <span class="n">zipcodeCount</span><span class="o"> =</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">zipcodeCount</span> <span class="o"><</span> <span class="nx">zipcodeLinks.size</span><span class="p">();</span> <span class="nx">zipcodeCount</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">System.out.println</span><span class="p">(</span><span class="nx">zipcodeLinks.get</span><span class="p">(</span><span class="nx">zipcodeCount</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
<p>zipCodesDiv contains the div that contains the zipcodes, however </p>
<p>zipCodesDiv.getByXPath("//li/a<span>[contains(@href,'propertyrecord-search/')]</span>");</p>
<p>is returning more content than it belongs in zipCodesDiv, it's also returning cities in Autauga County. Why is this happening? Is this a bug?</p>
<hr/>
<p>Sent from sourceforge.net because [email protected] is subscribed to <a href="https://sourceforge.net/p/htmlunit/bugs/">https://sourceforge.net/p/htmlunit/bugs/</a></p>
<p>To unsubscribe from further messages, a project admin can change settings at <a href="https://sourceforge.net/p/htmlunit/admin/bugs/options.">https://sourceforge.net/p/htmlunit/admin/bugs/options.</a> Or, if this is a mailing list, you can unsubscribe from the mailing list.</p></div>
--===============8775400093531972733==--
--===============7552512670075209791==--
--===============6430589295408891477==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============6430589295408891477==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
--===============6430589295408891477==--