我做了一个脚本,使用Simple HTML DOM解析器从另一个站点获取内容。它看起来像这样
include_once('simple_html_dom.php');
$html = file_get_html('http://csgolounge.com/'.$tradeid);
foreach($html->find('div[id=tradediv]') as $trade) {
$when = $trade->find('.tradeheader')[0];
}
我可能太频繁地寻找内容(每 30 秒一次),现在我得到空的 html。
我试图像这样更改用户代理
$context = stream_context_create();
stream_context_set_params($context, array('user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'r'n'));
$html = file_get_html('http://csgolounge.com/profile?id='.$steamid, 0, $context);
但我仍然得到空的html。
问题是我的html文件太大了。Simple html dom 定义了最大文件大小 define('MAX_FILE_SIZE', 600000)。我将其更改为 900000,现在它再次工作。