I'm creating a little script in Python to scrap from a site and store text and values in a sql database (I'm really a beginner on Python and sql).
A part of my code is:
def create_table():
c.execute('CREATE TABLE IF NOT EXISTS test(Match_Time TEXT, Team_1 TEXT, Team_2 TEXT, Tournament TEXT)')
create_table()
def data_entry():
c.execute("INSERT INTO matches(Match_Time, Team_1, Team_2) VALUES (?, ?)",
(e.text.strip(), e.text.strip(), e.text.strip()))
conn.commit()
table = driver.find_elements_by_css_selector("table[class='odds-data']")
for e in table:
if e.text is not "" and e.text.strip():
print e.text.strip()
data_entry() # to store in sql
The output from the site for example is the following:
12.00
Belgium
1.862
Over 2
1.813
Under 2
2.120
Sweden
5.250
***************
06.00
Poland
2.679
Over 2
2.320
Under 2
1.675
Switzerland
3.240
'*******' means another match
What I would like to do is to store the values and text from that output in a way that assign for every row in the output the correct column in sql.
Unfortunately I have no idea how to do, any suggestion?
Thanks to everyone for the help and sorry for my bad english
Aucun commentaire:
Enregistrer un commentaire