python - Fetching name and email from a web page -
this question exact duplicate of:
i'm trying fetch data off link. want fetch name/email/location/etc content web page , paste webpage. have written code when run code stores blank list.
please me copy these data web page.
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) companynameelement = browser.find_elements_by_css_selector(".content.clearfix>div>fieldset>div>ul>li").text companyname = companynameelement print companynameelement
the html code given below
<div class="content"> <div id="node-946273" class="node node-country node-promoted node-full clearfix"> <div class="content clearfix"> <div itemtype="http://schema.org/corporation" itemscope=""> <fieldset> <legend>company information</legend> <div style="width:100%;"> <div style="float:right; width:340px; vertical-align:top;"> <br/> <ul> <li> <strong>company name</strong> : <span itemprop="name">sabbro - f.z.c</span> </li> </ul>
when use it gives me error list' object has no attribute 'text'
. can me enhance code , make work. i'm kind of stuck forever on issue.
companynameelement = browser.find_elements_by_css_selector(".content.clearfix>div>fieldset>div>ul>li").text companyname = companynameelement print companynameelement
find_elements_by... return list, can either access first element of list or use equivalent find_element_by... method first element.
Comments
Post a Comment