【发布时间】:2015-09-18 04:33:12
【问题描述】:
我正在使用 Goutte 制作网页抓取工具。
为了开发,我保存了一个我想遍历的 .html 文档(所以我不会经常向网站发出请求)。到目前为止,这是我所拥有的:
use Goutte\Client;
$client = new Client();
$html=file_get_contents('test.html');
$crawler = $client->request(null,null,[],[],[],$html);
根据我所知道的应该在 Symfony\Component\BrowserKit 中调用 request,并传入原始正文数据。这是我收到的错误消息:
PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 7: Failed to connect to localhost port 80: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\Users\Ally\Sites\scrape\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.
如果我只使用 DomCrawler,那么使用字符串创建爬虫并非易事。 (见:http://symfony.com/doc/current/components/dom_crawler.html)。我只是不确定如何用 Goutte 做同样的事情。
提前致谢。
【问题讨论】:
-
“使用字符串创建爬虫的重要性”是什么意思? new Crawler(file_get_contents('test.html')) 有什么问题?
-
我将无法使用所有 Goutte 方法,例如 $crawler = $client->click($crawler->selectLink('Sign in')->link());
标签: php symfony web-scraping goutte