Is it possible to collect html source code using python?

Asked

Viewed 1,294 times

1

I would like something in python, some library that could access the site and get its source code (HTML). Example:

Talsite.com
<h1>hello</h1>

Is it possible for python to log into Talsite.com and collect its source code? If so, how?

I’m using python 2.7

1 answer

2


Python 2:

import urllib
url = "https://answall.com"
f = urllib.urlopen(url)
print f.read()

Python 3:

import urllib.request
url = "https://answall.com"
f = urllib.request.urlopen(url)
print(f.read())

Browser other questions tagged

You are not signed in. Login or sign up in order to post.