使用file_get_contents在php中进行屏幕截图 [英] Screen scapingin in php using file_get_contents
本文介绍了使用file_get_contents在php中进行屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对屏幕抓取非常陌生.我正在尝试从酒店预订网站上获取评论,以显示给我..
Hi I am very new to screen scraping. I am trying to scrape reviews from a hotel booking webite to display on to mine..
我已经走了很远,但是有点卡住了.有人可以帮忙吗?
Ive got this far but got a bit stuck. Can anyone help?
<?php
$data = file_get_contents('http://www.laterooms.com/en/hotel-reviews/238902_the-westfield-bb-sandown.aspx');
$regex = '/<div id="summary">
(.+?)</div>/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>
推荐答案
使用 DomDocument
<?php
define('URL', 'http://www.laterooms.com/en/hotel-reviews/238902_the-westfield-bb-sandown.aspx');
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents(URL));
$summary = $doc->getElementById('summary');
// also have $doc->getElementsByTagName , etc
var_export($summary);
?>
此外,对于更复杂的查询,您应该考虑研究 XPATH (类似于jQuery的语法)
Also, for more complicated queries you should consider looking into XPATH (uses jQuery-like syntax)
这篇关于使用file_get_contents在php中进行屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文