After updating to crawl4ai 0.4.1 version, i got error: "Couldn't find a tree builder with the features you requested: lxml.parser. Do you need to install a parser library?"
After updating to crawl4ai 0.4.1 version, when I write the following code, I get the following error. lxml is also installed, what causes the error?
from crawl4ai import WebCrawler
url_nm = 'http://news.bbc.co.uk/2/hi/business/7083015.stm'
crawler = WebCrawler()
crawler.warmup()
result = crawler.run(url=url_nm, word_count_threshold=10, bypass_cache=True)
result.extracted_content
[LOG] ๐ Initializing LocalSeleniumCrawlerStrategy
[LOG] ๐ค๏ธ Warming up the WebCrawler
[LOG] ๐ WebCrawler is ready to crawl
[LOG] ๐ Crawling done for http://news.bbc.co.uk/2/hi/business/7083015.stm, success: True, time taken: 4.64 seconds
[LOG] ๐ Content extracted for http://news.bbc.co.uk/2/hi/business/7083015.stm, success: True, time taken: 0.02 seconds
[LOG] ๐ฅ Extracting semantic blocks for http://news.bbc.co.uk/2/hi/business/7083015.stm, Strategy: NoExtractionStrategy
[LOG] ๐ Extraction done for http://news.bbc.co.uk/2/hi/business/7083015.stm, time taken: 0.02 seconds.
[ERROR] ๐ซ Failed to crawl http://news.bbc.co.uk/2/hi/business/7083015.stm, error: Couldn't find a tree builder with the features you requested: lxml.parser. Do you need to install a parser library?
่งฃๅณไบๅ๏ผๆไน้ๅฐไบๅๆ ท็้ฎ้ข๏ผๆไธๆธ ๆฅไธบไปไน
Did you solve it? I had the same problem, and I couldn't figure out why
Hi everyone, including @Zhangchunqin, @epzfnhql, and others,
As of version 0.4.x, the synchronous WebCrawler is no longer maintained. We recommend switching to the asynchronous AsyncWebCrawler. With recent versions, you donโt need additional parsers if you install the package as instructed.
Below is a sample code snippet demonstrating how to use AsyncWebCrawler along with BrowserConfig and CrawlerRunConfig. This approach gives you more control over the crawling process:
import asyncio
from crawl4ai import AsyncWebCrawler, BrowserConfig, CrawlerRunConfig, CacheMode
async def main():
# Configure browser
browser_config = BrowserConfig(headless=True, verbose=True)
# Set crawl run configurations
crawl_config = CrawlerRunConfig(cache_mode=CacheMode.BYPASS)
# Use AsyncWebCrawler
async with AsyncWebCrawler(browser_config=browser_config) as crawler:
result = await crawler.arun(
url="https://www.example.com",
config=crawl_config
)
print("Success:", result.success)
asyncio.run(main())
Please give this approach a try, and let us know if you have any questions!