【发布时间】:2020-08-18 11:34:24
【问题描述】:
from bs4 import BeautifulSoup as bs #importing the required libraries
from urllib.request import urlopen
import requests
urls1="https://www.makemytrip.com/hotels/" #initial url which contains the form where we could give our preferences.
#passing the data parameters
data={'checkin': '08152020',
'city': 'CTGOI',
'checkout': '08162020',
'roomStayQualifier': '2e0e',
'locusId': 'CTGOI',
'country': 'IN',
'locusType': 'city',
'searchText': 'Goa, India',
'visitorId': '5c68c2fb-0551-4ef2-8dae-1a55bb744e66'
}
req=requests.post(urls1,data, headers={'User-Agent': 'XYZ/3.0'})
page_soup = bs(req.content,"html.parser")
print(page_soup)
实际上我想抓取上述数据字段下的酒店,这就是为什么我将带有requests.post方法的数据参数发送到初始url,这样当我收到响应对象时,我会得到下一页的内容将包含符合上述要求的酒店。
【问题讨论】:
-
请格式化您的代码。这里没有问题
-
您好,先生,实际上我想通过 requets.post 方法发送其他数据,例如签入、结帐、地点等,这样当完成后,我将获得的响应对象将包含所有数据参数中提到的酒店列表,以便我可以抓取它。
-
您能否通过写下您面临的相同问题来更新问题?如果您可以显示打印输出,它也会有所帮助。您可以使用这样的东西来提取: page_soup.find("input", {"id": "some_id"})["value"]
-
Bendik Knapstad ,页面汤只包含初始网址的内容,我不想要。我想要点击搜索时下一页的内容(填写地点等详细信息后,签到、结账时间等)
-
谢谢大家的建议真的非常感谢!
标签: python dictionary web-scraping beautifulsoup python-requests