|
| 1 | +--- |
| 2 | +title: Web Crawling with Python and WebSkrap |
| 3 | +description: Build browser-aware Python web crawlers with WebSkrap, async concurrency, persistent sessions, resource policies, and safe crawling boundaries. |
| 4 | +--- |
| 5 | + |
| 6 | +# Web Crawling with Python and WebSkrap |
| 7 | + |
| 8 | +WebSkrap is useful for browser-aware web crawling when each URL may need JavaScript rendering, cookies, redirects, or a realistic browser profile. |
| 9 | + |
| 10 | +A crawler should still be polite and bounded. Respect robots policies where applicable, rate limits, terms of service, and access controls. WebSkrap does not include CAPTCHA solving or access-control bypassing. |
| 11 | + |
| 12 | +## Simple async crawl pattern |
| 13 | + |
| 14 | +```python |
| 15 | +import asyncio |
| 16 | + |
| 17 | +from webskrap import WebSkrapClient |
| 18 | + |
| 19 | +URLS = [ |
| 20 | + "https://example.com", |
| 21 | + "https://example.com/about", |
| 22 | +] |
| 23 | + |
| 24 | + |
| 25 | +async def main() -> None: |
| 26 | + async with WebSkrapClient() as client: |
| 27 | + results = await asyncio.gather(*(client.fetch(url) for url in URLS)) |
| 28 | + |
| 29 | + for result in results: |
| 30 | + print(result.status, result.final_url, result.title) |
| 31 | + |
| 32 | + |
| 33 | +asyncio.run(main()) |
| 34 | +``` |
| 35 | + |
| 36 | +## Crawl with sessions |
| 37 | + |
| 38 | +Use sessions when multiple pages belong to the same site and should share browser state. |
| 39 | + |
| 40 | +```python |
| 41 | +from pathlib import Path |
| 42 | +from webskrap import SessionConfig, WebSkrapClient |
| 43 | + |
| 44 | +config = SessionConfig(user_data_dir=Path(".webskrap/crawl-profile")) |
| 45 | +``` |
| 46 | + |
| 47 | +Persistent sessions can keep cookies and local storage between fetches for sites you are authorized to access. |
| 48 | + |
| 49 | +## Practical crawler tips |
| 50 | + |
| 51 | +- Keep concurrency low until you understand a site. |
| 52 | +- Use resource policies to avoid downloading heavy assets. |
| 53 | +- Store `final_url` to detect redirects and canonical pages. |
| 54 | +- Capture screenshots only for debugging because they add cost. |
| 55 | +- Log status codes, titles, timings, and failures. |
| 56 | + |
| 57 | +## Related docs |
| 58 | + |
| 59 | +- [Client API](/docs/user-guide/client) |
| 60 | +- [Sessions](/docs/user-guide/sessions) |
| 61 | +- [Profiles](/docs/user-guide/profiles) |
| 62 | +- [Resource policy](/docs/user-guide/resource-policy) |
0 commit comments