Menu

how to mimic cookie?

Help
2011-07-03
2013-04-09
  • Nobody/Anonymous

    Hello,

    I have found this software very useful. I am now trying to crawl a website that is only accessed when there is a certain cookie stored in my browser. The website does this to present information specific to a city selected. Is there a way I could mimic this cookie in my phpcrawl code?

     
  • Uwe Hunfeld

    Uwe Hunfeld - 2011-07-05

    Hi,

    "Injecting" cookies is not supported directly by phpcrawl (yet).

    But a little workaround should do the trick:
    Within your extended crawler-class, just overrdie the constructor and place your cookie into the internal cookie-array.

    So if your code now looks like this and you want to add a cookie for the site www.anysite.net with the name "cookie_name" and the value "cookie_value"

    // ...
    class MyCrawler extends PHPCrawler
    {
      function handlePageData(&$page_data)
      {
        // ... 
      }
    } 
    // ...
    

    replace it with this one:

    // ... 
    class MyCrawler extends PHPCrawler
    {
      function __construct()
      {
        parent::__construct();
        $this->pageRequest->cookies["anysite.net"]["cookie_name"] = "cookie_value";
        // Use "anysite.net" here, NOT "www.anysite.net"
      }
      
      function handlePageData(&$page_data)
      {
        //...
      } 
    } 
    // ...
    

    Hope it works for you!

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.