PHP获取网页内容 [英] PHP Get contents of webpage
本文介绍了PHP获取网页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在使用 PHP简单HTML DOM解析器来获取网页的内容.知道自己在做的事是对的之后,我仍然得到一个错误,那就是找不到任何东西.
So I am using the PHP Simple HTML DOM Parser to get the contents of a webpage. After I knew what I was doing was right, I still got the error that there was nothing to be found.
所以这是我用来查看是否有任何实际被捕获的东西:
So here's what I am using to see if there is anything actually being caught:
<?php
include_once('simple_html_dom.php');
error_reporting(E_ALL);
ini_set('display_errors', '1');
$first_url = "http://www.transfermarkt.co.uk/en/chinese-super-league/startseite/wettbewerb_CSL.html"; // works
$html = file_get_html($first_url);
echo "<textarea>Output\n===========\n $html</textarea><br /><br />";
$second_url = "http://www.transfermarkt.co.uk/en/chinese-super-league/torschuetzen/wettbewerb_CSL.html"; // does not work?
$html = file_get_html($second_url);
echo "<textarea>Output\n===========\n $html</textarea><br />";
?>
没有错误.在第二个文本区域中没有任何内容.第二个网址似乎没有被该工具刮掉……为什么?
No errors. Nothing in the 2nd textarea. The second URL does not seem to be getting scraped bt the tool... why?
推荐答案
simple_php_dom.php
包含:
define('MAX_FILE_SIZE', 600000);
...
if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
{
return false;
}
第二页超过672000字节,因此此大小检查失败.增大该常数,您就可以了.
The second page is over 672000 bytes, so this size check fails. Increase that constant and you should be OK.
这篇关于PHP获取网页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文