Menu

Set a variable that can be accessed in handleDocumentInfo

Help
Anonymous
2015-01-21
2015-01-21
  • Anonymous

    Anonymous - 2015-01-21

    Is is possible to set a variable on a crawler object or so that could then be accessed inside
    the handleDocumentInfo function override?

    For example:
    Before I run the crawl I have a customer ID known at initialization that should be written into DB for every handleDocumentInfo.
    url, status, customerID

    The customerID is taken from DB and is the same for all crawled URLs.

     
  • Uwe Hunfeld

    Uwe Hunfeld - 2015-01-21

    Hi!

    Just add a property "customuerID" to your extednen crawler-class, something like this:

    class MyCrawler extends PHPCrawler 
    {
      public $customerID;
    
      function handleDocumentInfo($DocInfo) 
      {
         // ...
         db_insert($DocInfo->url, $this->customerID, ...);
      }
    }
    
    $crawler = new MyCrawler;
    $crawler->customerID = 3948;
    // ...
    $crawler->go();
    

    That's why phpcrawl relies on OO-inheritance, there's no need for variables that get passed through, just extend the main-class with whatever you need in your project.

     
  • Anonymous

    Anonymous - 2015-01-21

    Hi Uwe!

    Thank you, thats fantastic. I see that I need to refresh my OO knowledge:)

     

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.