如何webscrape Tripadvisor酒店的href链接?

时间:2019-07-30 09:24:35

标签: python selenium-webdriver

我想抓取tripadvisor.in的数据。我成功抓取了姓名,但无法抓取href链接。如果没有链接,它应该离开
空字符串。下面是我的代码

 from selenium import webdriver
 from selenium.webdriver.common.by import By
 from selenium.webdriver.support.ui import Select
 import time
 import csv
 import pdb
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.support import expected_conditions as EC
 from selenium.common.exceptions import TimeoutException
 driver = webdriver.Firefox(executable_path = './geckodriver')
 url = ('https://www.tripadvisor.in/Hotels-g295424-Dubai_Emirate_of_Dubai-Hotels.html')
 driver.get(url)
 time.sleep(20)
 for elem in driver.find_elements_by_xpath('.//a[contains(@class,"property_title")]/@href'):
     print(elem.get_attribute('href'))

0 个答案:

没有答案