0

so far my cURL code i have written displays the page that I would like after it automatically logs me into a website, however i am stuck on the issue of screen scraping. I would like to now sort through some more information from this data. here is what i want to sort out of the page:

<div class="quantity">
    Avail. Quantity:<span>75</span>
</div>

I specifically would like to grab the number inside the <span> which in this case would be 75. how could i do this with curl?

Any suggestions on how to do this?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Thomas
  • 2,356
  • 7
  • 23
  • 59
  • Are you trying to read a web page and want to extract data from it? – Jeune Nov 12 '11 at 06:55
  • yes. i used curl because i had to log into the web page to view it, and now i would like to extract data from the page that i've logged into – Thomas Nov 12 '11 at 07:26

1 Answers1

3

You can use DOMDocument or one of the simpler library frontends like phpQuery or QueryPath. Then it's as easy as using a CSS selector:

print htmlqp($url)->find(".quantity span")->text();

(Note that page retrieval is already built-in here, but you could also just pass your $html variable.)

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
  • i installed it but im getting an error saying: Fatal error: Call to undefined function text() in /home/frostyc/public_html/crawl.php on line 73 – Thomas Nov 12 '11 at 07:25
  • Ah, evil syntax typo. It was missing a `->` (so tried to call a global function instead). – mario Nov 12 '11 at 07:28