解决 The ‘more_itertools‘ package is required

在使用爬虫获取维基百科数据时看到了一个很好的项目:

博客:https://blog.51cto.com/u_15919249/5962100

项目地址:https://github.com/wjn1996/scrapy_for_zh_wiki

但在使用过程中遇到若干问题,记录一下:

The 'more_itertools' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.:

解决方案:

或许并不是环境本身的问题。

  1. pip show more_itertools没有则安装,有则下一步
  2. 把queue.py 文件及该文件中的Queue类均重命名分别为myqueue.py 与 MyQueue。
  3. 将重命名后的myqueue.py放到spiders文件夹下,
  4. 将spider下单wiki.py 中的from queue import Queue修改为from .myqueue import MyQueue
    原因可能是Python中自带queue库,而博主这里是想调用自己的queue。

后面同样要把filter_words.py文件拿到spider下,并修改wiki中的from filter_words import filter_url 为from .filter_words import filter_url

在wiki.py繁简转换中加判断,避免输入为空

'''

def Traditional2Simplified(sentence):

'''

将sentence中的繁体字转为简体字

:param sentence: 待转换的句子

:return: 将句子中繁体字转换为简体字之后的句子

'''

sentence = Converter('zh-hans').convert(sentence)

return sentence

if sentence:

sentence = Converter('zh-hans').convert(sentence)

return sentence

else:

return sentence

'''

在wiki.py中修改

'''

content_entity = search.xpath("//h1[@id='firstHeading']/text()").extract_first()

content_entity = search.xpath("//h1[@id='firstHeading']/span/text()").extract_first()

'''

相关推荐
AI_Claude_code9 分钟前
ZLibrary访问困境方案三:Web代理与轻量级转发服务的搭建与优化
爬虫·python·web安全·搜索引擎·网络安全·web3·httpx
深蓝电商API5 小时前
代理 IP 池在跨境电商爬虫的使用
爬虫·跨境电商
ZC跨境爬虫7 小时前
批量爬取小说章节并优化排版(附完整可运行脚本)
前端·爬虫·python·自动化
AI_Claude_code9 小时前
ZLibrary访问困境方案二:DNS-over-HTTPS/TLS配置与隐私保护实践
爬虫·python·网络协议·http·网络安全·https·网络爬虫
小白学大数据10 小时前
告别复杂 XPath:DeepSeek+Python 爬虫快速实践
开发语言·爬虫·python·selenium
AI_Claude_code10 小时前
ZLibrary访问困境方案六:自建RSS/Calibre内容同步服务器的完整指南
运维·服务器·网络·爬虫·python·tcp/ip·http
AI_Claude_code11 小时前
安全与合规核心:匿名化、日志策略与法律风险规避
网络·爬虫·python·tcp/ip·安全·http·网络爬虫
专注API从业者21 小时前
淘宝商品详情 API 与爬虫技术的边界:合法接入与反爬策略的技术博弈
大数据·数据结构·数据库·爬虫
ZC跨境爬虫1 天前
Scrapy工作空间搭建与目录结构解析:从初始化到基础配置全流程
前端·爬虫·python·scrapy·自动化
电商API_180079052471 天前
基于 Python 实现淘宝京东商品数据 API 批量获取
java·前端·爬虫·python·数据分析