zero_shubham1

fiverr_project_2

Sep 2nd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.28 KB | None | 0 0
  1. from selenium.webdriver.common.keys import Keys
  2. from selenium import webdriver
  3. import time
  4. import csv
  5.  
  6.  
  7. def main():
  8.     browser= webdriver.Firefox()
  9.     for i in range(1,2):
  10.         temp_data=['Name','Sex','Age','Place','Availability','Facebook','Twitter','Soundcloud']
  11.         write(temp_data)
  12.         browser.get("https://www.sonicbids.com/find-musicians/?page_number="+str(i)+"&page_size=71")
  13.         time.sleep(3)
  14.         for j in range(1,73):
  15.             try:
  16.                 all_detail=list()
  17.                 btn=browser.find_element_by_xpath('/html/body/div[4]/main/div/div/section/div/div[2]/ol/li['+str(j)+']/a[1]')
  18.                 btn=browser.find_element_by_xpath('/html/body/div[4]/main/div/div/section/div/div[2]/ol/li['+str(j)+']/a[1]')
  19.                 btn.click()
  20.                 time.sleep(2)
  21.                 name=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[1]/div/div/h1').text)
  22.                 place=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[1]/div/div/header/address').text)
  23.                 try:
  24.                     sex=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[1]/div/div/header/span[4]').text)
  25.                     age=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[1]/div/div/header/span[2]').text)
  26.                 except:
  27.                     sex=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[1]/div/div/header/span[2]').text)
  28.                     age='z Not-Specified'
  29.                 try:
  30.                     avail= browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[1]/div/p[2]/span[2]').text
  31.                 except:
  32.                     avail='z Not-Specified'
  33.                 try:
  34.                     fb=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[1]/div/ol/li[1]/a').get_attribute('href'))
  35.                     tw=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[1]/div/ol/li[2]/a').get_attribute('href'))
  36.                     sc=(browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[1]/div/ol/li[3]/a').get_attribute('href'))
  37.                 except:
  38.                     fb=browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[2]/div/ol/li[1]/a').get_attribute('href')
  39.                     tw=browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[2]/div/ol/li[2]/a').get_attribute('href')
  40.                     sc=browser.find_element_by_xpath('/html/body/div[4]/section/div/section/div[2]/div[2]/div/ol/li[3]/a').get_attribute('href')
  41.                 all_detail=[name,sex,age.split()[1],place,avail,fb,tw,sc]
  42.                 print(all_detail)
  43.                 write(all_detail)
  44.                 print(all_detail)
  45.                 time.sleep(2)
  46.                 browser.find_element_by_xpath('/html/body/div[4]/section/header/a/span').click()
  47.             except:
  48.                 browser.refresh()
  49.     browser.quit()
  50.  
  51. def write(data):
  52.     with open('music.csv','a',newline='\n') as csvfile:
  53.         writer= csv.writer(csvfile, delimiter='~')
  54.         writer.writerow([data[0]]+[data[1]]+[data[2]]+[data[3]]+[data[4]]+[data[5]])
  55. if __name__ == '__main__':
  56.     main()
Add Comment
Please, Sign In to add comment