()
| 34 | print(result.markdown[:500]) # Print first 500 characters |
| 35 | |
| 36 | async def simple_example_with_running_js_code(): |
| 37 | print("\n--- Executing JavaScript and Using CSS Selectors ---") |
| 38 | # New code to handle the wait_for parameter |
| 39 | wait_for = """() => { |
| 40 | return Array.from(document.querySelectorAll('article.tease-card')).length > 10; |
| 41 | }""" |
| 42 | |
| 43 | # wait_for can be also just a css selector |
| 44 | # wait_for = "article.tease-card:nth-child(10)" |
| 45 | |
| 46 | async with AsyncWebCrawler(verbose=True) as crawler: |
| 47 | js_code = [ |
| 48 | "const loadMoreButton = Array.from(document.querySelectorAll('button')).find(button => button.textContent.includes('Load More')); loadMoreButton && loadMoreButton.click();" |
| 49 | ] |
| 50 | result = await crawler.arun( |
| 51 | url="https://www.nbcnews.com/business", |
| 52 | js_code=js_code, |
| 53 | # wait_for=wait_for, |
| 54 | bypass_cache=True, |
| 55 | ) |
| 56 | print(result.markdown[:500]) # Print first 500 characters |
| 57 | |
| 58 | async def simple_example_with_css_selector(): |
| 59 | print("\n--- Using CSS Selectors ---") |
no test coverage detected
searching dependent graphs…