开发者

PHP Screen-scraping methods

开发者 https://www.devze.com 2023-01-10 16:48 出处:网络
I have a site http://www.coldwellbankerpbr.com/listings.aspx that I am trying to grab the listings from, now I need the address and bedroom details, etc however there is no unique identifier besides t

I have a site http://www.coldwellbankerpbr.com/listings.aspx that I am trying to grab the listings from, now I need the address and bedroom details, etc however there is no unique identifier besides the text Address (which is repeated several times on t开发者_开发百科he page) I was looking at PHP DOM however that seems to be more of a looking for unique tags (div id's, etc).

Is there any more method I should be looking at for this more text based Address ****** search? The table is something like:

<td width="55">Address</td><td>ADDRESS HERE</td>

Thanks!


I would try XPath if i were you. for example with SimpleXml

$path = "/html/body/form[@id='main']/table/tbody/tr[4]/td/table/tbody/tr/td[1]/table/tbody/tr/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[2]"

$xml = new SimpleXmlElement('http://www.coldwellbankerpbr.com/listings.aspx', null, true);
$addresses = $xml->xpath($path);

foreach($addresses as $address) {
  echo $address;
}

That XPath should get you the actual text of the addresses for the listings. But you can play with it and read up on XPath to get just about anything you want. In fact you can probably simplify that path a bit.. i just generated in the XPather extension in Firefox to save myself some hassle :-) You can also use XPath with DOMDocument but its a little more complicated to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消