我的计算机上有270MB的数据集(10000个html文件)。我可以使用Scrapy在本地抓取此数据集吗?怎么样?
答案 0 :(得分:30)
如果你真的想在本地托管并使用scrapy,你可以通过导航到它存储的目录并运行SimpleHTTPServer(如下所示的端口8000)来提供它:
python -m SimpleHTTPServer 8000
然后在127.0.0.1:8000点scrapy。
$ scrapy crawl 127.0.0.1:8000
另一种方法是直接将scrapy指向文件集:
$ scrapy crawl file:///home/sagi/html_files # Assuming you're on a *nix system
为scrapy设置刮刀后(请参阅example dirbot),只需运行抓取工具:
$ scrapy crawl 127.0.0.1:8000
如果html文件中的链接是绝对的而不是相对的,那么这些链接可能效果不佳。您需要自己调整文件。
答案 1 :(得分:10)
转到数据集文件夹:
import os
files = os.listdir(os.getcwd())
for file in files:
with open(file,"r") as f:
page_content = f.read()
#do here watever you want to do with page_content. I guess parsing with lxml or Beautiful soup.
无需去Scrapy!