繼在YouTube上的教程: Scraping Web Pages with Scrapy Python的網頁抓取腳本,下面的教程和有問題
這是老,爲Python 2.x和我學習版本3.x到目前爲止,我遇到了幾個我通過Google可以找到的問題。不過目前,我得到一個錯誤:
File "/usr/lib64/python3.5/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks current.result = callback(current.result, *args, **kw) File "/home/skeer/PycharmProjects/scrape_craigslists/scrape_cl/scrape_cl/spiders/scrape.py", line 11, in parse xpath = scrapy.selector(response) TypeError: 'module' object is not callable
早些時候谷歌搜索,我發現引用到其他有這是由於非大寫字符,就好像「S」的選擇應該是資本。試了一下,並與scrapy.Selector模塊無法找到一個錯誤迎接。
這裏是我的代碼:
from scrapy.spider import Spider
import scrapy.selector
class MySpider(Spider):
name = "craigslist"
allowed_domains = ["craigslist.org"]
start_urls = ["https://helena.craigslist.org/search/sad"]
def parse(self, response):
xpath = scrapy.selector(response)
titles = xpath.select("//p")
for titles in titles:
title = xpath("/body/section/form/div/li/p[@class]()").extract()
link =
xpath("/body/section/form/div/ul/li/a[@href]").extract()
print (title, link)