Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named 'sgmllib' #2

Open
Bluetooth503 opened this issue Nov 24, 2016 · 1 comment
Open

ImportError: No module named 'sgmllib' #2

Bluetooth503 opened this issue Nov 24, 2016 · 1 comment

Comments

@Bluetooth503
Copy link

你好。你的这个项目非常有意义,我也有相同的需求。
我是一个Python初学者。对于代码部分有些疑问。
我安装了Python3.5的版本,我暂时还没弄懂如何启动MongoDB,所以先先把结果保存为csv文件:
scrapy crawl google -o test.csv JOBDIR=app/jobs

但是我得到如下错误信息:
ImportError: No module named 'sgmllib'

我在网上查找原因,得知SgmlLinkExtractor & LinkExtractor都需要sgmllib的支持。而Python3.0不支持sgmllib。所以我是不是需要重新安装Python2.7的环境?还有别的替代方法吗?

另外我也很好奇,在Google Play “Viber”页面下,获取app id和下载次数后,爬虫又是如何去爬下一个App的,这个循环是如何实现的?
rules = [
Rule(LinkExtractor(allow=("https://play.google.com/store/apps/details", )), callback='parse_app',follow=True),
] # CrawlSpider 会根据 rules 规则爬取页面并调用函数进行处理
这一段代码看不明白。

我自己可以使用BeautifulSoup+Request爬取某一个App的名称和下载量信息,但是我做不到爬取所有App的一个循环,也没办法让任务中断后,可接着爬取,而不用重新开始。

@oa414
Copy link
Owner

oa414 commented Nov 25, 2016

你好, Scrapy 的文档 上写着,最新版本支持Python2.7 和 Python 3.3+(Windows 下不支持 Python 3)。

如果你用是 Windows 系统,我建议你尝试安装 Python 2.7 来试试。你可以用 Virtualenv 方便地来在系统中安装管理多个 Python 版本。

LinkExtractor 是 Scrapy 内建的一个 Extractor,它的作用就是从页面中分析所有链接,符合这个 LinkExtractor 规则的都会给你抽取出来,继续爬取。

自己手写爬虫遍历的思路是把当前已经处理过的页面 url 保存到数据库或者磁盘,中断之后重新爬取的时候,从保存的状态恢复而不是从头再来。 简单的思路是把当前的程序的数据定时序列化(比如用 pickle)到一个文件中,启动的时候先读取磁盘的状态来初始化 url。

当然 Scrapy 背后帮你做了很多这样的工作,比如从页面中抽取 url,url 有没有重复,并发爬取的时候的状态共享,都帮你解决了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants