docs: Add guide "HttpCrawler with custom parser"#1622
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1622 +/- ##
==========================================
- Coverage 92.49% 92.48% -0.02%
==========================================
Files 157 157
Lines 10439 10439
==========================================
- Hits 9656 9654 -2
- Misses 783 785 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Thanks for the guide Max. While the code contained in there works, the idea was to use AbstractHttpCrawler along with a custom implementation of AbstractHttpParser - similarly to how BeautifulSoupCrawler and company are implemented.
The cool thing about this is that you can then use the parser class in AdaptivePlaywrightCrawler as well.
Got it. What do you think about expanding this guide with another section on implementation based on |
Well, just adding it to the bottom won't cut it, but you can make the guide into two parts - quick and dirty solution and the "native" way. You can also explain the benefits of each approach. |
| async def final_step( | ||
| context: ParsedHttpCrawlingContext[LexborHTMLParser], | ||
| ) -> AsyncGenerator[SelectolaxLexborContext, None]: | ||
| yield SelectolaxLexborContext.from_parsed_http_crawling_context(context) | ||
|
|
||
| # Build context pipeline: HTTP request -> parsing -> custom context. | ||
| kwargs['_context_pipeline'] = ( | ||
| self._create_static_content_crawler_pipeline().compose(final_step) | ||
| ) |
There was a problem hiding this comment.
It'd be nice to mention that these are not strictly necessary, you only need this if you want "idiomatic" helpers on the context (parser in this case). If you don't mind sticking with parsed_content, you can skip a lot of boilerplate.
There was a problem hiding this comment.
I think we should mention that this step is optional in a comment or something right here.
vdusek
left a comment
There was a problem hiding this comment.
Looks great!
I'm also updating the description to note that this resolves #702 as well, due to saxonche.
However, I would say this content would fit better in the HTTP crawlers guide. I'd suggest merging it there.
"Using HttpCrawler with a custom parser" could be the next section after "HttpCrawler", and "Creating a custom crawler" is essentially the same as "Creating a custom HTTP crawler".
docs/guides/code_examples/crawler_custom_parser/selectolax_adaptive_run.py
Show resolved
Hide resolved
…ptive_run.py Co-authored-by: Jan Buchar <Teyras@gmail.com>
vdusek
left a comment
There was a problem hiding this comment.
This is really good, thanks!
Just a few minor things... Mostly regarding more concise titles and consistent grammatical forms.
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
vdusek
left a comment
There was a problem hiding this comment.
One more nit. Otherwise LGTM.
| async def final_step( | ||
| context: ParsedHttpCrawlingContext[LexborHTMLParser], | ||
| ) -> AsyncGenerator[SelectolaxLexborContext, None]: | ||
| yield SelectolaxLexborContext.from_parsed_http_crawling_context(context) | ||
|
|
||
| # Build context pipeline: HTTP request -> parsing -> custom context. | ||
| kwargs['_context_pipeline'] = ( | ||
| self._create_static_content_crawler_pipeline().compose(final_step) | ||
| ) |
There was a problem hiding this comment.
I think we should mention that this step is optional in a comment or something right here.
Co-authored-by: Jan Buchar <Teyras@gmail.com>
Description
Issues