Anyone has a PHP function that can grab all links inside a specific DIV on a remote site? So usage might be:
$links = grab_links($url,$divname);
And return an array I can use. Grabbing links I can figure out but not sure how to make it only do it within a specific div.
Thanks! Scott
Check out PHP XPath. It will let you query a document for the contents of specific tags and so on. The example on the php site is pretty straightforward: http://php.net/manual/en/simplexmlelement.xpath.php
This following example will actually grab all of the URLs in any DIVs in a doc:
$xml = new SimpleXMLElement($docAsString);
$result = $xml->xpath('//div//a');
You can use this on well-formed HTML files, not just XML.
Good XPath reference: http://msdn.microsoft.com/en-us/library/ms256086.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With