Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I access items once all item pipelines are finished? #35

Closed
adzay opened this issue Apr 10, 2022 · 2 comments
Closed

How do I access items once all item pipelines are finished? #35

adzay opened this issue Apr 10, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@adzay
Copy link

adzay commented Apr 10, 2022

I am running unit tests and i want to get all items scraped into an array. I plan to show the results in a Vue componenent so I need to return the results from a Laravel controller.

I am getting phpUnit logs that the terms have been successfully crawled. However the below results produces a null result.

$customs = Roach::startSpider(CustomSpider::class);

//roach.INFO: Run starting [] []
//roach.INFO: Item scraped {"name":"xxx"} []
//roach.INFO: Item scraped {"name":"xxx2"} []


   foreach ($customs as $cus) {
            dd($cus);
        }

//foreach() argument must be of type array|object, null given

Please help I have read your docs but it talks about handling data within the generator (itemsPipeline), nothing about exporting results.

Thanks

@ksassnowski ksassnowski self-assigned this Apr 17, 2022
@ksassnowski ksassnowski added this to the 1.0.0 milestone Apr 17, 2022
@ksassnowski ksassnowski added the enhancement New feature or request label Apr 17, 2022
@ksassnowski
Copy link
Contributor

This will be part of the upcoming 1.0 release. A new method Roach::collectSpider(...) will get added that behaves the exact same way as Roach::startSpider(...) except that it will return all scraped items after the run.

// $scrapedItems is an array<int, ItemInterface>
$scrapedItems = Roach::collectSpider(MySpider::class);

@ksassnowski
Copy link
Contributor

This is possible in the 1.0 release. Please check out this section of the docs for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants