roach-php / core

The complete web scraping toolkit for PHP.

Home Page:https://roach-php.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

item->get('key'); does not work as expected

rabol opened this issue · comments

After runnung the spider like this

        $items = Roach::collectSpider(SpainOnAForkSpider::class);

I do

        foreach( $items as $item)
        {
          debug($item->get('json'));
        }

result is

null

a dump of $items like this:

^ array:1 [▼
  0 => RoachPHP\ItemPipeline\Item {#524 ▼
    -data: array:2 [▼
      0 => "json"
      1 => "{"@context":"https://schema.org","@graph":[{"@type":"Article","@id":"https://spainonafork.com/authentic-spanish-seafood-paella-recipe/#article","isPartOf":{"@id ▶"
    ]
    -dropReason: ""
    -dropped: false
  }
]

Item was not created correctly in the spider class

this is what I did:

 yield $this->item(['json', $json]);

this is correct

 yield $this->item(['json' => $json]);