小编Ton*_*niD的帖子

File_get_html在PHP Simple HTML DOM Parser中返回空的html

我创建了一个脚本,它使用Simple HTML DOM Parser从另一个站点获取内容.看起来像这样

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];
 }
Run Code Online (Sandbox Code Playgroud)

我可能经常寻找内容(每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);
Run Code Online (Sandbox Code Playgroud)

但我仍然回到空的HTML.

php user-agent simple-html-dom

1
推荐指数
1
解决办法
2030
查看次数

标签 统计

php ×1

simple-html-dom ×1

user-agent ×1