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

Spider #62

Closed
roniemartinez opened this issue Mar 7, 2022 · 0 comments · Fixed by #90
Closed

Spider #62

roniemartinez opened this issue Mar 7, 2022 · 0 comments · Fixed by #90
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@roniemartinez
Copy link
Owner

roniemartinez commented Mar 7, 2022

Possible ways to implement a simple Spider

### Expose "scraper" object in the handler functions

@select(css="a")
def get_link(element, scraper):  # <-- pass scraper object
    url = element.get_attribute("href")
    scraper.follow(url)  # <-- add to the URLs that will be scraped by the scraper 
    return {"url": url}

### Include the URLs in return

@select(css="a")
def get_link(element):
    url = element.get_attribute("href")
    return {"url": url}, [url, ...]  # <- return a tuple of dict result and list of URLs

Final implementation

Just use --follow-urls or pass follow_urls=True to run(). #90
This is less complicated when compared to managing the URLs to crawl by yourself inside the code.

WARNING: Do not use until #27 is implemented as this option will crawl indefinitely and will not save the data.

@roniemartinez roniemartinez added enhancement New feature or request help wanted Extra attention is needed labels Mar 7, 2022
@roniemartinez roniemartinez self-assigned this Mar 19, 2022
@roniemartinez roniemartinez mentioned this issue Mar 19, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant