当前位置: 首页 > news >正文

开题报告 网站建设游戏平台网站开发

开题报告 网站建设,游戏平台网站开发,建材有限公司,网站建设竞品调研github项目--crawl4ai 输出html输出markdown格式输出结构化数据与BeautifulSoup的对比 crawl4ai github上这个项目,没记错的话,昨天涨了3000多的star,今天又新增2000star。一款抓取和解析工具,简单写个demo感受下 这里我们使用cra…

github项目--crawl4ai

    • 输出html
    • 输出markdown格式
    • 输出结构化数据
    • 与BeautifulSoup的对比

crawl4ai github上这个项目,没记错的话,昨天涨了3000多的star,今天又新增2000star。一款抓取和解析工具,简单写个demo感受下

这里我们使用crawl4ai抓取github每日趋势,每天通过邮件发到自己邮箱

输出html

async def github_trend_html():async with AsyncWebCrawler(verbose=True) as crawler:result = await crawler.arun(url="https://github.com/trending",)assert result.success, "github 数据抓取失败"return result.cleaned_html

输出的还是html,但对原始页面做了处理,比如移除不相关元素,动态元素,简化html结构。

在这里插入图片描述

输出markdown格式

async def github_trend_md():async with AsyncWebCrawler(verbose=True) as crawler:result = await crawler.arun(url="https://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[itemprop='programmingLanguage']",},{"name": "stars","type": "text","selector": "a[href*='/stargazers']"},{"name": "today_star","type": "text","selector": "span.float-sm-right",},],}extraction_strategy = JsonCssExtractionStrategy(schema, verbose=True)async with AsyncWebCrawler(verbose=True) as crawler:result = await crawler.arun(url="https://github.com/trending",extraction_strategy=extraction_strategy,bypass_cache=True,)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提取结构化数据的能力(尚未体验)
http://www.yayakq.cn/news/410606/

相关文章:

  • 外国做水吧设计的网站建设公司网站需要注意哪些
  • 手机网站搭建平台中卫网站推广优化公司
  • 模板网站建设+百度北京个人制作网站
  • 如何申请免费的网站临漳网站建设
  • 做百度网站好吗wordpress定义字体颜色
  • 建设一元云购类网站wordpress一键拨号
  • 电商网站开发图书seo 对网站有什么影响
  • 网站图片翻页怎么做深圳规模较大的网站建设公司
  • 人人站cmswordpress 右侧有个赞助商
  • 建设跳转公积金网站网站建设要做哪些前期准备工作
  • 好的网页网站设计网站文章怎么更新时间
  • 哪里有做区块链网站的天津seo公司
  • 网站免费正能量不下载青岛网站有限公司
  • 一家做土产网站wordpress 未加密
  • 东莞网站建设快速排名网站服务器 数据库服务器
  • 个人网站 组建投资网站建设公司
  • 番禺网站开发服务网站建设公司要多少钱
  • 上海网站建设开发哪家好句容建设网站
  • 安徽网站优化好不好怎么描述网站主页做的好
  • 我的网站 dedecmswordpress 一键排版
  • 百度新网站提交入口alexa排名前三十
  • 建设网站500错误宿州网站建设费用
  • 网站wap版影响权重么网络营销是什么研究
  • 徐州开发的网站如何建设传奇网站
  • 做出口的网站宁德网页设计
  • 做网站 每月赚 钱wordpress扒站教程
  • 模板网站免费自己的网站没有域名
  • 网站平台定制开发少儿编程加盟费多少钱
  • 海南住房与建设厅网站网络营销的10个特点
  • 定州网站设计网站培训机构有哪些