2
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?

2
  • what do you mean displaying table in python? Commented Jul 25, 2013 at 5:24
  • What you're doing here is more widely known by the term "scraping". Just thought you might find it useful when googling for examples and such. Commented Jul 25, 2013 at 16:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Any suggestions on how to parse a table from a website using python, and also storing it into a csv file?
Check out the following question. It will help you. stackoverflow.com/questions/15250455/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.