我是新來的scrapy,但使用python一段時間。我從scrapy
文檔以及xpath
選擇器中吸取了教訓。現在,我想將知識轉化爲一個小項目。我正嘗試使用scrapy從作業板https://www.germanystartupjobs.com/
中取消job links and the associated info like job title, location, emails (if any), phone numbers (if any)
。如何使用scrapy獲取href和相關信息?
我有這樣的起動代碼,
import scrapy
class GermanSpider(scrapy.Spider):
# spider name
name = 'germany'
# the first page of the website
start_urls= ['https://www.germanystartupjobs.com/']
print start_urls
def parse(self, response):
pass
def parse_detail(self, response):
pass
和運行蜘蛛scrapy runspider germany
裏面的parse
功能,我想獲得的parse_detail
函數內href
S和細節。
的時候,我跟chrome
開發工具打開提到的頁面,並檢查列出的作業,我看到所有的工作都是在這裏面ul
<ul id="job-listing-view" class="job_listings job-listings-table-bordered">
,然後,將中隔離作業中所列出的許多的
<div class="job-info-row-listing-class">
與關聯的相關信息divs
,也就是說,href
的內部設置<a href="https://www.germanystartupjobs.com/job/foodpanda-berlin-germany-2-sem-manager-mf/">
其他divs
提供職位,公司名稱,地址等與divs
如
<div>
<h4 class="job-title-class">
SEM Manager (m/f) </h4>
</div>
<div class="job-company-name">
<normal>foodpanda<normal> </normal></normal></div>
</div>
<div class="location">
<div class="job-location-class"><i class="glyphicon glyphicon-map-marker"></i>
Berlin, Germany </div>
</div>
的第一步將是獲得href
使用parse
功能,然後,將parse_details
內的相關信息使用response
。我發現email
和phone
號碼僅在您打開href
的鏈接時提供,但標題和位置在同一頁的當前divs
內提供。
正如我所提到的,我在Python中編程的技巧還不錯,但是,即使在使用tutorial之後,我仍然在使用xpath
s。如何找到鏈接和相關信息?一些示例代碼很少有解釋,將會有所幫助。
我嘗試使用代碼
# firstly
for element in response.css("job-info-row-listing-class"):
href = element.xpath('@href').extract()[0]
print href
yield scrapy.Request(href, callback=self.parse_detail)
# secondly
values = response.xpath('//div[@class="job-info-row-listing-class"]//a/text()').extract()
for v in values:
print v
#
values = response.xpath('//ul[@id="job-listing-view"]//div[@class="job-info-row-listing-class"]//a/text()').extract()
他們似乎很容易使用乳寧scrapy runspider germany
感謝您的回答,這真的很有幫助。我發佈了另一個與'scrapy'相關的問題,可能會對你有所幫助'http:// stackoverflow.com/questions/41178659/how-to-get-the-job-description-using-scrapy' – Chak