只是嘗試scrapy,並試圖獲得一個基本的蜘蛛工作。我知道這可能只是我想念的東西,但我已經嘗試了所有我能想到的東西。Scrapy HtmlXPathSelector
我得到的錯誤是:
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()
你如何運行你的蜘蛛? 'scrapy抓取「google.com」'? – Leo
你的代碼沒有問題(除了不需要再聲明SPIDER),它對我來說很有用。 –
@Leo這就是我一直在運行它。 –