0
我無法使用scapry按照「下一頁」的鏈接 - 根據日誌它是指自己而不是「下一頁」的網址。下面是代碼:Scrapy引用回原來的頁面而不是下一頁
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes2"
start_urls = [
'http://search.jeffersondeeds.com/pdetail.php?instnum=2016230701&year=2016&db=0&cnum=20',
]
def parse(self, response):
for quote in response.xpath('//div'):
yield{
'record' : quote.select(".//span/text()").extract()
}
next_page = response.xpath('//*[@id="nextpage"]/a/@href').extract()
if next_page is not None:
print("GOOOO BUCKS!!")
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page, callback=self.parse)
else:
print("Ahhh fooey!")
中的XPath看起來是正確的:
但被捕獲爲next_page的網址是原來的URL(starts_urls)
有什麼'print'你設定的輸出? – eLRuLL
它打印「GOOOO BUCKS !!」。我添加了一個print(next_page),它打印出原始URL(不是鏈接中的那個) –
請調試你的代碼,next_page不是None,但它是一個空的列表,並且我看到了正在生成的實際下一頁鏈接一個javascript裏面的'//表// //腳本/文本()' – eLRuLL