0
import urllib2
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
url = ("http://www.justdial.com/Mumbai/CA")
driver = webdriver.Firefox()
driver.get(url)
driver
elements = driver.find_elements_by_xpath('//div[@class="col-md-12 col-xs-12 padding0"]')
for e in elements:
print e.text
url = driver.current_url
company_name = driver.find_element_by_xpath('//span[@class="jcn"]').text
contact_number = driver.find_element_by_xpath('//p[@class="contact_info"]').text
address = driver.find_element_by_xpath('//p[@class="adress_info"]').text
address_info = driver.find_element_by_xpath('//p[@class="address-info adinfoex"]').text
estd = driver.find_element_by_xpath('//li[@class="fr"]').text
ratings = driver.find_element_by_xpath('//li[@class="last"]').text
tf = 'textfile.csv'
f2 = open(tf, 'a+')
f2.write(', '.join([data.encode('utf-8') for data in [company_name]]) + ',')
f2.write(', '.join([data.encode('utf-8') for data in [contact_number]]) + ',')
f2.write(', '.join([data.encode('utf-8') for data in [address]]) + ',')
f2.write(', '.join([data.encode('utf-8') for data in [address_info]]) + ',')
f2.write(', '.join([data.encode('utf-8') for data in [estd_ratings]]) + '\n')
f2.close()