MCPcopy
hub / github.com/unclecode/crawl4ai / interactive_extraction

Function interactive_extraction

docs/examples/quickstart_sync.py:167–182  ·  view source on GitHub ↗
(crawler)

Source from the content-addressed store, hash-verified

165 print_result(result)
166
167def interactive_extraction(crawler):
168 # Passing JavaScript code to interact with the page
169 cprint("\n🖱️ [bold cyan]Let's get interactive: Passing JavaScript code to click 'Load More' button![/bold cyan]", True)
170 cprint("In this example we try to click the 'Load More' button on the page using JavaScript code.")
171 js_code = """
172 const loadMoreButton = Array.from(document.querySelectorAll('button')).find(button => button.textContent.includes('Load More'));
173 loadMoreButton && loadMoreButton.click();
174 """
175 # crawler_strategy = LocalSeleniumCrawlerStrategy(js_code=js_code)
176 # crawler = WebCrawler(crawler_strategy=crawler_strategy, always_by_pass_cache=True)
177 result = crawler.run(
178 url="https://www.nbcnews.com/business",
179 js = js_code
180 )
181 cprint("[LOG] 📦 [bold yellow]JavaScript Code (Load More button) result:[/bold yellow]")
182 print_result(result)
183
184def multiple_scrip(crawler):
185 # Passing JavaScript code to interact with the page

Callers 1

mainFunction · 0.85

Calls 3

cprintFunction · 0.85
print_resultFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…