「次のページ」のリンクに従うためにscapryを使用する際に問題があります。次のページの代わりに元のページに戻って参照する治療
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が元のURL(starts_urls)である
'あなたが設定print'の出力は何ですか? – eLRuLL
「GOOOO BUCKS !!」と表示されます。私はprint(next_page)を追加して元のURLを表示します(リンクのものではありません) –
コードをデバッグしてください、next_pageはNoneではありませんが、空のリストであり、実際のnextpageリンクは'' // table // script/text() ''の中のjavascript – eLRuLL