Skip to content Skip to sidebar Skip to footer

Retreiving Data From A Website

I'm terribly sorry if this is unacceptable or answered elsewhere, but I've spent the last hour and a half looking for information on it, and have come up with nothing I can use. I'

Solution 1:

You have the site variable pointed to the return value of urllib.request.urlopen. In the next line, you call site.read(), which returns a string. In short, site is not referencing a string; it's referencing a response object which can be used to get the string content.

Since you already know site.read() returns a string, why not capture that as a variable and use it?

content = site.read()
print(content)

Solution 2:

Instead of printing the results of site.read(), store it in a variable, which will be a string containing all the text of the page, which you can then do with whatever you need to.


Post a Comment for "Retreiving Data From A Website"