python爬取酒店列表_用python怎样爬取酒店网站的价格?

本文介绍如何使用Python的requests和lxml库从万豪酒店官网爬取北京地区的酒店价格。通过设置特定URL参数,获取并解析HTML,提取出酒店价格信息。
摘要由CSDN通过智能技术生成

你试试这个地址:

"http://www.marriott.com.cn/search/submitSearch.mi?pageType=editsearch&searchType=InCity&miniStoreFormSubmit=false&initialRequest=false&recordsPerPage=20&vsInitialRequest=false&dimensions=&marriottBrands=all&poiName=&poiCity=&destinationAddress.latitude=39.906011&destinationAddress.longitude=116.387911&destinationAddress.cityPopulation=0.0&destinationAddress.cityPopulationDensity=0.0&airportCode=&singleSearchAutoSuggest=true&autoSuggestItemType=city&destinationAddress.latitude=39.906011&destinationAddress.longitude=116.387911&destinationAddress.cityPopulation=0.0&destinationAddress.cityPopulationDensity=0.0&singleSearch=true&destinationAddress.city=%E5%8C%97%E4%BA%AC&destinationAddress.stateProvince=&destinationAddress.country=CN&airportCode=&for-hotels-nearme=%E9%9D%A0%E8%BF%91&is-hotelsnerame-clicked=false&destinationAddress.destination=%E5%8C%97%E4%BA%AC%2C+China&fromDate=&toDate=&flexibleDates=false&roomCount=1&guestCount=1&useRewardsPoints=false&marriottRewardsNumber=&clusterCode=none&corporateCode="

参数自己配置一下,城市参数什么的,代码如下:

import requests

from lxml import html

_url = 'http://www.marriott.com.cn/search/findHotels.mi'

_headers = {

'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',

'Accept-Encoding':'gzip, deflate, sdch',

'Accept-Language':'zh-CN,zh;q=0.8',

'Connection':'keep-alive',

'Host':'www.marriott.com.cn',

'Referer':'http://www.marriott.com.cn/default.mi',

'Upgrade-Insecure-Requests':'1',

'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'

}

resp = requests.get(_url, headers= _headers)

cookies = resp.cookies

url ="http://www.marriott.com.cn/search/submitSearch.mi?searchType=InCity&groupCode=&searchRadius=&poiName=&poiCity=%E5%8C%97%E4%BA%AC&recordsPerPage=20&for-hotels-nearme=%E9%9D%A0%E8%BF%91&destinationAddress.destination=%E5%8C%97%E4%BA%AC%2C+China&singleSearch=true&singleSearchAutoSuggest=false&autoSuggestItemType=Unmatched&clickToSearch=false&destinationAddress.latitude=39.906011&destinationAddress.longitude=116.387911&destinationAddress.cityPopulation=0.0&destinationAddress.cityPopulationDensity=0.0&destinationAddress.city=%E5%8C%97%E4%BA%AC&destinationAddress.stateProvince=&destinationAddress.country=CN&airportCode=&fromToDate=7+%E6%9C%88+28%E6%97%A5%2C+%E5%91%A8%E5%9B%9B&fromToDate_submit=2016-07-28&fromDate=2016-07-28&toDate=2016-07-29&lengthOfStay=1&roomCountBox=1&roomCount=1&guestCountBox=1&guestCount=1&clusterCode=none&corporateCode="

r = requests.get (url, headers = _headers, cookies = cookies)

body = html.fromstring(r.text)

sub = body.xpath('//span[@class="t-price"]')

print(sub[0].text)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值