I am scraping manulife刮網頁包含錨標記<a href = "#"> using scrapy
我想進入下一個頁面,當我檢查了「下一個」我得到:
<span class="pagerlink">
<a href="#" id="next" title="Go to the next page">Next</a>
</span>
還有什麼是正確的做法遵循?
# -*- coding: utf-8 -*-
import scrapy
import json
from scrapy_splash import SplashRequest
class Manulife(scrapy.Spider):
name = 'manulife'
#allowed_domains = ['https://manulife.taleo.net/careersection/external_global/jobsearch.ftl?lang=en']
start_urls = ['https://manulife.taleo.net/careersection/external_global/jobsearch.ftl?lang=en&location=1038']
def start_requests(self):
for url in self.start_urls:
yield SplashRequest(
url,
self.parse,
args={'wait': 5},
)
def parse(self, response):
#yield {
# 'demo' : response.css('div.absolute > span > a::text').extract()
# }
urls = response.css('div.absolute > span > a::attr(href)').extract()
for url in urls:
url = "https://manulife.taleo.net" + url
yield SplashRequest(url = url, callback = self.parse_details, args={'wait': 5})
#self.log("reaced22 : "+ url)
#hitting next button
#data = json.loads(response.text)
#self.log("reached 22 : "+ data)
#next_page_url =
if next_page_url:
next_page_url = response.urljoin(next_page_url)
yield SplashRequest(url = next_page_url, callback = self.parse, args={'wait': 5})
def parse_details(self,response):
yield {
'Job post' : response.css('div.contentlinepanel > span.titlepage::text').extract(),
'Location' : response.xpath("//span[@id = 'requisitionDescriptionInterface.ID1679.row1']/text()").extract(),
'Organization' : response.xpath("//span[@id = 'requisitionDescriptionInterface.ID1787.row1']/text()").extract(),
'Date posted' : response.xpath("//span[@id = 'requisitionDescriptionInterface.reqPostingDate.row1']/text()").extract(),
'Industry': response.xpath("//span[@id = 'requisitionDescriptionInterface.ID1951.row1']/text()").extract()
}
正如您所看到的,代碼包含SplashRequest,同時打到下一頁的鏈接。
我是刮菜的新手,在某處我發現該網站可以返回響應爲json也。我試過了,但它給我的錯誤,「沒有JSON對象可以解碼」
我已經嘗試過使用scrapy-splash,但是沒有結果。 –
scrapy無法解釋JavaScript,請將硒用於此類事情。 – shotgunner
我已經使用了用於處理javascript請求的scrapy-splash。 @shotgunner –