你试试这个地址:
"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)