只是尝试scrapy并试图让一个基本的蜘蛛工作。我知道这可能只是我想念的东西,但我已经尝试了我能想到的一切。
我得到的错误是:
line 11, in JustASpider
sites = hxs.select('//title/text()')
NameError: name 'hxs' is not defined
我的代码目前非常基本,但我似乎仍然找不到哪里出错了。谢谢你的帮助!
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
class JustASpider(BaseSpider):
name = "google.com"
start_urls = ["http://www.google.com/search?hl=en&q=search"]
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//title/text()')
for site in sites:
print site.extract()
SPIDER = JustASpider()