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

Function multiple_scrip

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

Source from the content-addressed store, hash-verified

182 print_result(result)
183
184def multiple_scrip(crawler):
185 # Passing JavaScript code to interact with the page
186 cprint("\n🖱️ [bold cyan]Let's get interactive: Passing JavaScript code to click 'Load More' button![/bold cyan]", True)
187 cprint("In this example we try to click the 'Load More' button on the page using JavaScript code.")
188 js_code = ["""
189 const loadMoreButton = Array.from(document.querySelectorAll('button')).find(button => button.textContent.includes('Load More'));
190 loadMoreButton && loadMoreButton.click();
191 """] * 2
192 # crawler_strategy = LocalSeleniumCrawlerStrategy(js_code=js_code)
193 # crawler = WebCrawler(crawler_strategy=crawler_strategy, always_by_pass_cache=True)
194 result = crawler.run(
195 url="https://www.nbcnews.com/business",
196 js = js_code
197 )
198 cprint("[LOG] 📦 [bold yellow]JavaScript Code (Load More button) result:[/bold yellow]")
199 print_result(result)
200
201def using_crawler_hooks(crawler):
202 # Example usage of the hooks for authentication and setting a cookie

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…