【问题标题】:Set cookie for a specific domain in PHPCrawl在 PHPCrawl 中为特定域设置 cookie
【发布时间】:2012-05-28 07:44:50
【问题描述】:

我使用PHPCrawl 抓取网站,但现在我想将cookie 添加到特定域,因为该域具有身份验证并且我想在授权页面中获取信息。

如何将 cookie 添加到特定域?

【问题讨论】:

    标签: php cookies phpcrawl


    【解决方案1】:

    最后我找到了一种将cookie添加到特定域的方法:

    我将像这样在自己的爬虫类中重载 __construct:

    class MyCrawler extends PHPCrawler 
    {
        function __construct() { 
            parent::__construct();
    
            $s = new PHPCrawlerCookieDescriptor("localhost", "JSESSIONID", "DE7BCB89B0D5BB072357450F01415FAB");
            $f[] = $s;
            $this->PageRequest->addCookieDescriptors($f);
        }
    }
    

    现在您应该有一个带有 JSESSIONID 名称和 DE7BCB89B0D5BB072357450F01415FAB 的 cookie,因为它的价值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 2020-07-14
      • 2018-01-28
      • 2023-04-10
      • 1970-01-01
      • 2014-09-15
      • 2021-12-01
      • 2012-01-28
      相关资源
      最近更新 更多