city_name="Goa"
# trip dates
year="2019"
start_month="06"
start_date="21"
end_month="06"
end_date="23"
start_total=year+start_month+start_date # combine the start date
end_total=year+end_month+end_date # combine the end date
# guest and room details
room_count ="1"
adults="2"
children="0"
child_age="3"
room=room_count+"-"+adults+"-"+children+"-"+child_age # combined room details
url="https://www.goibibo.com/hotels/find-hotels-in-"+city_name+"/" \
"8717279093827200968/8717279093827200968/" \
"%7B%22ci%22:%22"+start_total+"%22,%22co%22:%22"+end_total+"%22," \
"%22r%22:%22"+room+"%22%7D/?{}&sec=dom"
main_page_data=driver.get(url)
driver.set_window_position(-3000, 0)
posts = driver.find_elements_by_css_selector("div.width100 fl")
for i in range(1,100):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
t.sleep(1)
soup = BeautifulSoup(driver.page_source, "lxml")
links = soup.find_all('div', {"class": "width100 fl ico20"})
for i in links:
print(i)
driver.quit()
我正在尝试向下滚动页面以访问网站中的所有酒店。该网站在页面滚动中加载酒店。 在此代码中,我仅获得三个酒店的详细信息。 直到最后一页才滚动。