I want to select contact information by selenium on the website below:
http://buyersguide.recyclingtoday.com/search.
For matching the right information one by one, I want to select the rows first, and then select information from the rows. The simple code as below, my question now is how to select the information from each row. For example, company name, email.
Code:
from time import sleep from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait as wait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import NoSuchElementException import pandas as pd driver = webdriver.Chrome('D:\chromedriver_win32\chromedriver.exe') driver.get('http://buyersguide.recyclingtoday.com/search') rows = driver.find_elements_by_xpath('//*[@id="Body_tbl"]/tbody/tr') for row in rows: email = row.find_element_by_xpath('//*/tr/td[3]/a').text company=row.find_element_by_xpath('//*/tr/td[1]').text Run the code as answers below, but I still face problem?
from time import sleep from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait as wait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import NoSuchElementException import pandas as pd driver = webdriver.Chrome('D:\chromedriver_win32\chromedriver.exe') driver.get('http://buyersguide.recyclingtoday.com/search') rows = driver.find_elements_by_xpath('//*[@id="Body_tbl"]/tbody/tr') records = [] for row in rows: company=row.find_element_by_xpath('./td[1]').text address = row.find_element_by_xpath('./td[2]').text contact= row.find_element_by_xpath('./td[3]//a').text number= row.find_element_by_xpath('./td[5]').text records.append((company,address,contact,number)) df = pd.DataFrame(records, columns=['company','number','address', 'contact']) No content selected