免费网络短剧网站,霸州网站制作,短视频平台推广方案,怎么样推广一个网站github项目--crawl4ai 输出html输出markdown格式输出结构化数据与BeautifulSoup的对比 crawl4ai github上这个项目#xff0c;没记错的话#xff0c;昨天涨了3000多的star#xff0c;今天又新增2000star。一款抓取和解析工具#xff0c;简单写个demo感受下 这里我们使用cra… github项目--crawl4ai 输出html输出markdown格式输出结构化数据与BeautifulSoup的对比 crawl4ai github上这个项目没记错的话昨天涨了3000多的star今天又新增2000star。一款抓取和解析工具简单写个demo感受下 这里我们使用crawl4ai抓取github每日趋势每天通过邮件发到自己邮箱 输出html
async def github_trend_html():async with AsyncWebCrawler(verboseTrue) as crawler:result await crawler.arun(urlhttps://github.com/trending,)assert result.success, github 数据抓取失败return result.cleaned_html输出的还是html但对原始页面做了处理比如移除不相关元素动态元素简化html结构。 输出markdown格式
async def github_trend_md():async with AsyncWebCrawler(verboseTrue) as crawler:result await crawler.arun(urlhttps://github.com/trending,)assert result.success, github 数据抓取失败return result.markdown用md软件打开看一下效果 输出结构化数据
async def github_trend_json():schema {name: Github trending,baseSelector: .Box-row,fields: [{name: repository,selector: .lh-condensed a[href],type: text,},{name: description,selector: p,type: text,},{name: lang,type: text,selector: span[itempropprogrammingLanguage],},{name: stars,type: text,selector: a[href*/stargazers]},{name: today_star,type: text,selector: span.float-sm-right,},],}extraction_strategy JsonCssExtractionStrategy(schema, verboseTrue)async with AsyncWebCrawler(verboseTrue) as crawler:result await crawler.arun(urlhttps://github.com/trending,extraction_strategyextraction_strategy,bypass_cacheTrue,)assert result.success, github 数据抓取失败github_trending_json json.loads(result.extracted_content)for ele in github_trending_json:ele[repository] https://github.com/ .join(ele[repository].split())return github_trending_json与前两种不同的是结构化输出需要通过自定义schema来定义解析的数据结构。控制台按照我们定义的schema输出了标准了JSON数据。将数据放入html模版通过邮件每日发送。看一下邮件显示 与BeautifulSoup的对比 记得第一次用soup的时候对于只用过Java sax解析xml的我来说soup真的太方便了。今天简单测试了下crawl4ai和soup相比 crawl4ai数据采集分析更方便soup需要配合使用request进行网页抓取BeautifulSoup负责html解析html解析有点类似都是通过CSS选择器但crawl4ai通过定义schema解析更方便数据解析方面crawl4ai除了提供了markdown和简化版的html还提供了通过集成OpenAI提取结构化数据的能力(尚未体验)