php|architect's Guide to Web Scraping with PHP - Wind Business ...
php|architect's Guide to Web Scraping with PHP - Wind Business ...
php|architect's Guide to Web Scraping with PHP - Wind Business ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CSS Selec<strong>to</strong>r Libraries ” 131<br />
About Us<br />
Contact Us<br />
<br />
<br />
<br />
<br />
<br />
<br />
• #nav would select the div element because it has an id attribute value of nav.<br />
• li would select all li elements by their node name.<br />
• .horizontal would select the ul element because it has a class of horizontal.<br />
(Note that elements can have multiple classes.)<br />
• * would select all elements in the document.<br />
• li, a would select all li and a elements in the document by combining the<br />
two selec<strong>to</strong>rs li and a in<strong>to</strong> a comma-delimited list.<br />
H e r e are the XPath equivalents along side their respective CSS counterparts. Aside<br />
from the .class selec<strong>to</strong>r, the XPath expressions are not significantly longer or more<br />
complex.<br />
Selec<strong>to</strong>r CSS XPath<br />
id #nav //*[@id=“nav”]<br />
element li //li<br />
class .horizontal //*[@class=“horizontal”<br />
or starts-<strong>with</strong>(@class, “horizontal ”)<br />
or contains(@class, “ horizontal ”)<br />
or ends-<strong>with</strong>(@class, “ horizontal”)]<br />
wildcard * //*<br />
multiple li, a //li|//a