crawl4ai icon indicating copy to clipboard operation
crawl4ai copied to clipboard

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?"

Open epzlfnql opened this issue 1 year ago โ€ข 3 comments

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?

epzlfnql avatar Dec 11 '24 10:12 epzlfnql

่งฃๅ†ณไบ†ๅ—๏ผŒๆˆ‘ไนŸ้‡ๅˆฐไบ†ๅŒๆ ท็š„้—ฎ้ข˜๏ผŒๆžไธๆธ…ๆฅšไธบไป€ไนˆ

Zhangchunqin avatar Dec 12 '24 01:12 Zhangchunqin

Did you solve it? I had the same problem, and I couldn't figure out why

Zhangchunqin avatar Dec 12 '24 01:12 Zhangchunqin

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!

unclecode avatar Dec 13 '24 12:12 unclecode