1

I am learning scraping using the PHP Simple HTML DOM Parser and Xpath. Accroding to the changelog given here http://sourceforge.net/news/?group_id=218559. The PHP SImple HTML DOM Parser supports xpath generated from Firebug. But I am not able to figure out how to use it. Can anyone show me an example of the same...

2 Answers 2

3

The find function. http://simplehtmldom.sourceforge.net/manual.htm#section_find

$content = file_get_html($link);

$elems = $content->find("/html/body/div/div");
Sign up to request clarification or add additional context in comments.

Comments

1

There's find function in Simple HTML DOM Parser. BUT it accepts selectors! So you cant just write

$html = file_get_html($link);
$elements = $html->find("/html/body/div/p");

because then you'll get more than one element!

to get just exact element marked by XPath, write

$element = $html->find("/html/body/div[1]/p[1]", 0);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.