Sag*_*agi 14 python web-crawler scrapy
我的计算机上有270MB的数据集(10000个html文件).我可以使用Scrapy在本地抓取此数据集吗?怎么样?
Kyl*_*ley 32
如果你真的想在本地托管它并使用scrapy,你可以通过导航到它所存储的目录来运行它并运行SimpleHTTPServer(如下所示的端口8000):
python -m SimpleHTTPServer 8000
Run Code Online (Sandbox Code Playgroud)
然后在127.0.0.1:8000指向scrapy
$ scrapy crawl 127.0.0.1:8000
Run Code Online (Sandbox Code Playgroud)
另一种方法是直接将scrapy指向文件集:
$ scrapy crawl file:///home/sagi/html_files # Assuming you're on a *nix system
Run Code Online (Sandbox Code Playgroud)
一旦你设置了scrapy的刮刀(参见示例dirbot),只需运行爬虫:
$ scrapy crawl 127.0.0.1:8000
Run Code Online (Sandbox Code Playgroud)
如果html文件中的链接是绝对的而不是相对的,那么这些链接可能效果不佳.您需要自己调整文件.
Rat*_*mar 10
转到您的Dataset文件夹:
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.
Run Code Online (Sandbox Code Playgroud)
没必要去Scrapy!