2
私はScrapを使用してdmoz.orgで何かを得るためのスパイダーを作成します。ScrapyはPythonシェルとcmd.exeで異なる結果を示します
Pythonシェルでresponse.xpath
を使用して確認すると、私が望むものが得られますが、このスパイダーをcmdで実行すると何も得られません。よくわかりません。ここで
は私の蜘蛛のコードです:
import scrapy
from kecheng3.items import Kecheng3Item
class DmozSpiderSpider(scrapy.Spider):
name = "dmoz_spider"
allowed_domains = ["dmoz.org"]
start_urls = ["http://www.dmoz.org/Computers/Programming/Languages/Python/Books/"]
def parse(self, response):
for divm in response.xpath('//*[@id="site-list-content"]/div'):
item = Kecheng3Item()
item['title'] = divm.xpath('/div[3]/a/div/text()').extract()
item['link'] = divm.xpath('/div[3]/a/@href').extract()
item['desc'] = divm.xpath('/div[3]/div/text()').extract()
yield item
おかげで、:
これがデフォルトである、あなたは、この方法を行うことができます – wnj