我一直在抓取一些网站以获取进行网页抓取练习的位置。这段代码让我了解了酒店品牌的各个城市级别,但是每当我在代码中使用 driver.execute_script("arguments[0].click();", button) 时(如倒数第二行所示),我得到这个错误:
JavascriptException: Message: javascript error: arguments[0].click is not a function
Run Code Online (Sandbox Code Playgroud)
下面是我迄今为止编写的代码示例。
for state in state_links:
driver = Chrome(path_to_chrome_driver)
link = 'https://www.ihg.com/destinations/us/en/united-states/' + state.lower().replace(' ', '-')
driver.get(link)
city_links = driver.find_elements_by_xpath('//div[@class="countryListingContainer col-xs-12"]//ul//div//li//a//span')
city_links = [thing.text for thing in city_links]
driver.close()
for city in city_links:
driver = Chrome(path_to_chrome_driver)
link2 = 'https://www.ihg.com/destinations/us/en/united-states/' + state.lower().replace(' hotels', '').replace(' ', '-') + '/' + city.lower().replace(' ', '-')
driver.get(link2)
hotel_links = driver.find_elements_by_xpath('//div[@class="hotelList-detailsContainer"]//div//div//p//a')
hotel_links = [elem.text for elem in hotel_links]
driver.close()
for hotel in hotel_links:
driver …
Run Code Online (Sandbox Code Playgroud) 我如何从 SQL 中重新创建 COALESCE() 方法,但在 python 中?