简体   繁体   中英

Reading webpages Python 3.6

Very new to Python and struggling to get the hang of it, im needing to retrieve a webpage via its url, and return its contents. The contents will be parsed later to find hyperlinks etc using regular expressions. (Im not wanting to use beautifulsoup)

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

I realise my answer is probably very wrong but any pointer in the right direction would be great.

In python 3.6 urlopen is in urllib.request module.

from urllib.request import urlopen

url = "http://stackoverflow.com"
f = urlopen(url)
print (f.read())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM