Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 如何使用Seleniu从该网站链接中获取所有数据,并将提取的城市、位置和联系人号码保存为csv数据框对象?_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Selenium 如何使用Seleniu从该网站链接中获取所有数据,并将提取的城市、位置和联系人号码保存为csv数据框对象?

Selenium 如何使用Seleniu从该网站链接中获取所有数据,并将提取的城市、位置和联系人号码保存为csv数据框对象?,selenium,selenium-webdriver,selenium-chromedriver,Selenium,Selenium Webdriver,Selenium Chromedriver,指向刮取数据的网站url 代码: 这是你问题的第一部分。从一开始,您需要等待所有元素加载到屏幕上。抓取为该位置保留的前2个TR之外的所有表格TR。使用./从tr xpath到其子级,并分别使用属性('textContent')获取td[1-3]文本 wait = WebDriverWait(driver, 60) driver.get("http://jawedhabib.co.in/hairandbeautysalons-sl/") #driver.maximize_wi

指向刮取数据的网站url

代码:


这是你问题的第一部分。从一开始,您需要等待所有元素加载到屏幕上。抓取为该位置保留的前2个TR之外的所有表格TR。使用./从tr xpath到其子级,并分别使用属性('textContent')获取td[1-3]文本

wait = WebDriverWait(driver, 60)
driver.get("http://jawedhabib.co.in/hairandbeautysalons-sl/")
#driver.maximize_window()
tableValues=wait.until(EC.presence_of_all_elements_located((By.XPATH,"//tbody//tr[position()>2]")))
city=[]
address=[]
contactno=[]
for tr in tableValues:
    #print(tr.get_attribute('textContent'))
    city.append(tr.find_element_by_xpath("./td[1]").get_attribute('textContent'))
    address.append(tr.find_element_by_xpath("./td[2]").get_attribute('textContent'))
    contactno.append(tr.find_element_by_xpath("./td[3]").get_attribute('textContent'))
进口

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

lst=driver.find_element_by_css_selector(“.post-17954.page.type page.status publish.hentry”)。lst中i的文本:driver.implicitly_wait(2)city=driver.find_element_by_css_selector(“tr”)。text沙龙地址=driver.find_element_by_css_selector(“tr”)。text Contact_number=driver.find_element_by_css_selector(“tr”).text print(lst)您的
lst
是一个字符串!您只需遍历字符串中的字符。重点是什么?你是说
lst=driver.find\u elements\u by\u css\u selector(“.post-17954.page.type page.status publish.hentry”)
?我想不出我将迭代并提取标签下提到的所有数据的元素。
city=I.find\u elements\u by\u css\u selector(“tr”).text
它在执行lst=driver后返回一些长代码段。通过lst:driver中的i的css\u选择器(“div.wpb\u包装器”)查找元素。隐式地等待(2)city=i.css\u选择器(“tr”)查找元素。text沙龙地址=i.css\u选择器(“tr”)查找元素。文本联系号码=i.css\u选择器(“tr”)查找元素.文本打印(lst)获取为该位置保留的前2个TR之外的所有表格TR。保留表是什么意思中央区城市沙龙地址联系人没有基本上忽略这些行我想添加一个用户代理,我正在这样做:from selenium.webdriver.chrome.options import options opts opts=options()opts.add_参数(“user agent=Mozilla/5.0(Windows NT 10.0;WOW64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/88.0.4324.190 Safari/537.36“)driver=webdriver.Chrome(Chrome_options=opts)但存在错误我正在获取未找到的文件错误,并引发webdriverexception消息:“chromedriver”可执行文件需要位于路径中。你需要设置你的chromedriver。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC