Reputation: 39
import urllib2
url = "http://www.bdfutbol.com/es/t/t2012-13.html"
request = urllib2.Request(url)
handle = urllib2.urlopen(request)
content = handle.read()
splitted_page = content.split('<div class="divclassificacio">', 1);
splitted_page = splitted_page[1].split("</div>", 1);
print "Downloads: " + splitted_page[0]
So I just wrote this code to retrieve data, in html, from a soccer website using python. I am having issues writing the result into a file, and also displaying the table in python, which is what the code's for.
Also, I was wondering if anybody knew how can I transfer the table or the data into a MySql table?
Upvotes: 2
Views: 207
Reputation: 4898
To write to a file you can use:
with open('downloads.txt', 'w') as output_file:
output_file.write(splitted_page[0])
In order to transfer into MySQL (or any other database) you'll have to first model your data in a schema, and then interact with it via the python interface. This set of articles provide great help on how to interact with databases from python.
Upvotes: 1