我是Python新手,成功安装了Scrapy,在eclipse中使用PyDev。当我运行程序时,它显示如下(如图所示)
[]
我正在运行这段代码:
import scrapy
class DmozSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = ["dmoz.org"]
start_urls = [
"http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
"http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
]
def parse(self, response):
for sel in response.xpath('//ul/li'):
title = sel.xpath('a/text()').extract()
link = sel.xpath('a/@href').extract()
desc = sel.xpath('text()').extract()
print title, link, desc
它是什么?无法运行程序。
您当前的目录不是 Scrapy 项目。
scrapy 项目具有定义的格式和文件。看一下:http://doc.scrapy.org/en/latest/intro/tutorial.html http://doc.scrapy.org/en/latest/intro/tutorial.html
您确实应该浏览一次教程。
基本上,Scrapy 项目的目录结构如下:
tutorial/
scrapy.cfg # deploy configuration file
tutorial/ # project's Python module, you'll import your code from here
__init__.py
items.py # project items file
pipelines.py # project pipelines file
settings.py # project settings file
spiders/ # a directory where you'll later put your spiders
__init__.py
...
要创建 scrapy 项目,请转到项目文件夹并运行:
scrapy startproject projectname
创建项目后,您现在可以从项目根文件夹运行 scrapy。确保运行 scrapy 时位于项目的根目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)