Repository navigation
Cannot wait_for css #696
Replies: 1 comment
|
I've tried the example in this page. Here the key issue is that there's interweaved So what would actually work for wait condition is Another catch is that Here's the code sample that would work for you import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
async def main():
js_condition="()=>{return document.querySelectorAll('tr.athing.submission')[29]}"
config = CrawlerRunConfig(
# Wait for at least 30 items on Hacker News
wait_for=f"js:{js_condition}",
)
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(
url="https://news.ycombinator.com",
config=config
)
print("We have at least 30 items loaded!")
# Rough check
print("Total items in HTML:", result.html.count("athing"))
if __name__ == "__main__":
asyncio.run(main())Thanks for bringing this up. I'll update the docs soon with a working example. |
Uh oh!
There was an error while loading. Please reload this page.
I test the code in https://docs.crawl4ai.com/core/page-interaction/
import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
async def main():
config = CrawlerRunConfig(
# Wait for at least 30 items on Hacker News
wait_for="css:.athing:nth-child(30)"
)
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(
url="https://news.ycombinator.com",
config=config
)
print("We have at least 30 items loaded!")
# Rough check
print("Total items in HTML:", result.cleaned_html.count("athing"))
if name == "main":
asyncio.run(main())
The result always returned time out even though I set page_timeout quite high. How can I fix it?
All reactions