使用 scrapy 爬取 微博热搜
安装 pip install Scrapy 创建项目 scrapy startproject weiboHotSearch 创建爬虫 cd weiboHotSearch scrapy genspider weibo s.weibo.com 编写Item 修改weiboHotSearch中的items.py,添加item import scrapy class WeibohotsearchItem(scrapy.Item): # define the fields for your item here like: # name = scrapy.Field() pass keyword = scrapy.Field() url = scrapy.Field() count = scrapy.Field() 编写爬虫 修改 start_urls ,注意为list格式 使用 xpath 解析数据 xpath语法可参考 https://www.w3school.com.cn/xpath/xpath_syntax.asp 解析数据时,可运行 scrapy shell "https://s.weibo.com/top/summary" 调试xpath 引入 Item ,将数据以 Itme 对象返回 执行 scrapy crawl weibo 运行爬虫 运行结果如下: weibo.py