V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
5wcxcom
V2EX  ›  程序员

提问以下 phantomjs 不好爬取头条的是什么情况屏蔽了吗

  •  
  •   5wcxcom · 2019-08-19 16:55:32 +08:00 · 1053 次点击
    这是一个创建于 1712 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如何搞呢?我发下代码 require 'vendor/autoload.php'; use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();

    $client->getEngine()->setPath('/www/wwwroot/phantomjs-2.1.1-linux-x86_64/bin/phantomjs'); //设置 phantomjs 位置 $client->getEngine()->addOption('--load-images=false'); $client->getEngine()->addOption('--ignore-ssl-errors=true'); $client->getEngine()->addOption('--local-to-remote-url-access=true'); $client->isLazy();// 让客户端等待所有资源加载完毕

    $url = $_REQUEST['url']; $url = 'https://m.toutiaoimg.cn/group/6695506106313080836/?app=news_article&timestamp=1558936734&share_ht_uid=58738473383&did=55927714761&utm_medium=toutiao_android&tt_from=copy_link'; $request = $client->getMessageFactory()->createRequest($url, 'GET');

    $timeout = 10000; //设置超时 $request->setTimeout($timeout);

    $request->addSetting('userAgent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3704.400 QQBrowser/10.4.3587.400');//设置 ua

    $response = $client->getMessageFactory()->createResponse(); $client->send($request, $response);

    $allHtml = $response->getContent(); print_r($allHtml);

    打开显示: 您访问的页面不存在

    它是做了什么处理吗?应该如何绕过呢?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2365 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:10 · PVG 00:10 · LAX 09:10 · JFK 12:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.