i have written a code that that can scrape few details from a webpage. My question is whenever i run my code it prints the output like
second question, how can i make my code look for professional? is my coding style bad? and how can i make it shorter?below is my code:
Output:|['Kapil Sarawagi' '[email protected]' '1412702594']| |['MA ARCHICTECTS PRIVATE LIMITED' '[email protected]' '1414299999']| |['Prabhu Dayal Kanojiya' '[email protected]' '9829055412']|
|['Kapil Sarawagi' '[email protected]' '1412702594']|
|['MA ARCHICTECTS PRIVATE LIMITED' '[email protected]' '1414299999']|
|['Prabhu Dayal Kanojiya' '[email protected]' '9829055412']|
like in each cell...how can i do it?second question, how can i make my code look for professional? is my coding style bad? and how can i make it shorter?below is my code:
import requests from bs4 import BeautifulSoup from urllib.request import urlopen import csv url = "http://www.rera-rajasthan.in/Home/ViewProject?id=JgMAAA" html = urlopen(url) soup = BeautifulSoup(html, "html.parser") finaldata = [] data = soup.find_all("div", {"class":"panel-body"}) #filename = "Rajasthan.csv" #f = open(filename, "r") for i in data:# to get engineer date = i.find_all("table", {"class":"table table-bordered"}) getname = date[21].find_all("td") name = getname[1].text email = getname[0].text phone = getname[3].text sublist = [] fname = [name, email, phone] sublist.append(fname) for i in data:# to extract architect date = i.find_all("table", {"class":"table table-bordered"}) getname = date[20].find_all("td") name = getname[1].text email = getname[0].text phone = getname[3].text #sublist = [] fname = [name, email, phone] sublist.append(fname) for i in data:# to extract contractor date = i.find_all("table", {"class":"table table-bordered"}) getname = date[19].find_all("td") name = getname[1].text email = getname[0].text phone = getname[3].text #sublist = [] fname = [name, email, phone] sublist.append(fname) finaldata.append(sublist) with open("output.csv", "w")as csvfile: writer = csv.writer(csvfile, delimiter=',',quotechar='|', lineterminator='\n') for i in range(0, len(finaldata)): writer.writerow(finaldata[i])