【发布时间】:2021-07-27 18:20:32
【问题描述】:
我已经在 Selenium 中编写了代码以在某些信息通过后抓取 Accor's booking website。我可以使用此代码在结果页面上抓取并返回所有酒店的名称。
url = 'https://all.accor.com/ssr/app/accor/hotels/london/index.en.shtml?dateIn=2021-08-20&nights=8&compositions=1&stayplus=false'
driver = webdriver.Chrome(executable_path='C:\\Users\\conor\\Desktop\\diss\\chromedriver.exe')
driver.get(url)
time.sleep(10)
working = driver.find_elements_by_class_name('hotel__wrapper')
for work in working:
name = work.find_element_by_class_name('title__link').text
name = name.strip()
print(name)
这会按预期返回页面上的所有酒店名称,但是,它还会返回一个包含每个酒店名称的额外行,以及酒店的星级,我在页面上的 HTML 标记中没有看到.这是输出。
Sofitel London St James
5 Star rating
The Savoy
5 Star rating
Mercure London Bloomsbury Hotel
4 Star rating
Novotel London Waterloo
4 Star rating
ibis London Blackfriars
3 Star rating
Novotel London Blackfriars
4 Star rating
Mercure London Bridge
4 Star rating
Novotel London Bridge
4 Star rating
ibis Styles London Southwark - near Borough Market
3 Star rating
Pullman London St Pancras
4 Star rating
有没有办法删除与酒店名称一起返回的评级的额外文本行?因为我只想要酒店名称,因为我使用这些名称来比较不同网站的价格。任何帮助表示赞赏,谢谢。
【问题讨论】:
-
您是否希望 Ibis Styles London Southwark 包含“ - 近自治市镇市场”?
标签: python selenium web-scraping selenium-chromedriver