python 2.7 - How to get data off from a web page in selenium webdriver -
i want fetch company name, email, phone number link , put these contents in excel file. want same pages of website. have got logic fetch the links in browser , switch in between them. i'm unable fetch data website. can provide me enhancement code have written.
below code have written:
from selenium import webdriver selenium.common.exceptions import nosuchelementexception selenium.webdriver.common.keys import keys import time lxml import html import requests import xlwt browser = webdriver.firefox() # local session of firefox # 0 wait until pages loaded browser.implicitly_wait(3) # 3 secs should enough. if not, increase browser.get("http://ae.bizdirlib.com/taxonomy/term/1493") # load page links = browser.find_elements_by_css_selector("h2 > a") #print link link in links: link.send_keys(keys.control + keys.return) link.send_keys(keys.control + keys.page_up) #tree = html.fromstring(link.text) time.sleep(5)
what have tried fetch data links? can show example. if want "s.s.d middle east - f.z.e", after click on link, has number of attributes ranging company name industry. if want locate , retrieve company name, need locate first , text:
companynameelement = browser.find_element_by_css_selector("div[class="region region-content"] span[itemprop="name"]"); companyname = companynameelement.gettext()
you should "s.s.d middle east - f.z.e" in companyname variable.
Comments
Post a Comment