【发布时间】:2021-12-12 08:14:49
【问题描述】:
include('/simple_html_dom.php');
$url = "https://www.2311666.com.tw/";
$opts = array(
'http'=> array('header'=>"User-Agent:Chrome/94.0.4606.81\r\n"));
$context = stream_context_create($opts);
$html = new simple_html_dom();
$get = file_get_contents($url,false,$context);
$html->load($get);
echo $html;
附:以上代码部署在服务器上。
我可以抓取大多数网站,但一些使用 WordPress 内部缓存的特定网站返回乱码。
更准确地说,第一次抓取正常,但第二次抓取显示乱码。
我尝试过使用 cURL 或动态用户代理,但得到了相同的结果。有正确的方法吗?
【问题讨论】:
标签: php web-scraping caching