Does spider support click? #300
Unanswered
squirrelfish
asked this question in
Q&A
Replies: 2 comments 2 replies
|
Hey! Yep, this works. Use a browser session and pass a from scrapling.spiders import Spider, Request, Response
from scrapling.fetchers import AsyncDynamicSession
async def click_through(page):
await page.click("a.entry-link")
await page.wait_for_load_state("networkidle")
class MySpider(Spider):
name = "clicker"
start_urls = ["https://example.com/entry"]
def configure_sessions(self, manager):
manager.add("browser", AsyncDynamicSession(headless=True))
async def parse(self, response: Response):
yield Request(
response.url,
sid="browser",
page_action=click_through,
callback=self.parse_target,
)
async def parse_target(self, response: Response):
yield {"title": response.css("h1::text").get()}Works the same whether the click loads a new page or just swaps content in place. Chain as many clicks or waits as you need inside |
0 replies
|
This is ok, but I have a new question, how do I click to turn the page ( js onclick, no direct url) |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Some websites don't have direct URLs for their target sections. You gotta click through the entry URLs to get there.
All reactions