-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
54 lines (45 loc) · 1.3 KB
/
Copy pathfile.py
File metadata and controls
54 lines (45 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from selenium import webdriver
import urllib2
from bs4 import BeautifulSoup
import MySQLdb
from pyquery import PyQuery
import json
import os
import requests
from html_table_extractor.extractor import Extractor
# db = MySQLdb.connect("directcallconnect.com","admin_default","echomartini","admin_default" )
db = MySQLdb.connect("148.66.136.54","rutherford","rf112233","rythunestham" )
# db = MySQLdb.connect("localhost","krishna","echomartini","krishna" )
## Initialize and load the web page
url = "http://agrimarketing.telangana.gov.in/indexnew.jsp"
driver = webdriver.PhantomJS()
driver.get(url)
html2 = driver.page_source
# print html2
soup = BeautifulSoup(html2)
table = soup.find('table', {'height': '450'})
extractor = Extractor(table)
extractor.parse()
data = extractor.return_list()
# print data
query = ''
print "extracted"
for i in data:
name = i[0]
minp = i[1]
maxp = i[2]
query = query+"('"+str(name)+"','"+str(minp)+"','"+str(maxp)+"'),"
query = query.replace('\n', '')
if name=="Comm.":
query = ''
# print query
sql = "INSERT INTO rates(name, min, max) VALUES "+query[:-1]
# Execute the SQL command
print sql
mycursor = db.cursor()
mycursor.execute(sql)
print "data inserted successfully"
# Commit your changes in the database
db.commit()
# disconnect from server
db.close()