我正在尝试从booking.com网站上提取酒店名称以及价格。我设法提取了酒店名称并将其存储在项目容器中,但是我正在努力从网页中提取相关价格。 我的代码如下:
import scrapy
from ..items import KonkurrenzanalyseItem
class Konkurrenzanalyse(scrapy.Spider):
name = 'Booking'
start_urls = [
'https://www.booking.com/searchresults.de.html?aid=304142&label=gen173nr-1DCAEoggI46AdIM1gEaDuIAQGYAQe4AQfIAQ3YAQPoAQGIAgGoAgO4AuadkPIFwAIB&sid=f5f5396810ee33128397135370be94ba&tmpl=searchresults&checkin_month=2&checkin_monthday=18&checkin_year=2020&checkout_month=2&checkout_monthday=19&checkout_year=2020&class_interval=1&dest_id=-1821233&dest_type=city&dtdisc=0&from_sf=1&group_adults=2&group_children=0&inac=0&index_postcard=0&label_click=undef&no_rooms=1&order=price&postcard=0&raw_dest_type=city&room1=A%2CA&sb_price_type=total&shw_aparth=1&slp_r_match=0&src_elem=sb&srpvid=704b677afe570188&ss=Lübeck&ss_all=0&ssb=empty&sshis=0&ssne=Lübeck&ssne_untouched=Lübeck&top_ufis=1&rows=25&offset=25'
]
def parse(self, response):
items = KonkurrenzanalyseItem()
hotel_name = response.css('.sr-hotel__name::text').extract()
hotel_price = response.css('.bui-price-display__value::text').extract()
items['hotel_name'] = hotel_name
items['hotel_price'] = hotel_price
yield items
由于我是这种环境中的新手,如果我的问题不是100%正确地提出,请原谅。
答案 0 :(得分:1)
在我看来,就像您的CSS选择器稍微关闭了一样,请尝试:
hotel_price = response.css('div.bui-price-display__value.prco-inline-block-maker-helper::text').extract_first()
看看这个有用的CSS slector资源here