Skip to content

Preferred way to use a search bar #608

Answered by janbuchar
afuetterer asked this question in Q&A

You must be logged in to vote

First off, I'd definitely advise you to use request labels to differentiate the request types, but you may already be doing that.

Regarding handling the search bar, there are multiple high level approaches. I'd probably make a request for each of your search terms like this:

start_requests = [
  Request.from_url(url=f"https://secret-search-engine.com#{term}", label="search", keep_url_fragment=True) 
  for term in search_terms
]

await crawler.run(start_requests)

In your handler for the search label, you can extract the fragment from context.request.url, enter it into the search bar and handle the results in any way you see fit.

Replies: 1 comment 5 replies

You must be logged in to vote
5 replies
@afuetterer

@janbuchar

@afuetterer

@janbuchar

Answer selected by afuetterer
@afuetterer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants