简体   繁体   中英

in my python 3 i cannot use urllib.request as it says i don't have this submodule so how can i access websites data?

I use python3 and urllib module has parse, error, robotparse only it does not commands like import urllib.request and urllib.request.urlopen so what the substitute or how to fix it

go through the documentation and using it re-install the urllib and then try or you can try this script instead

 from urllib.request import urlopen
 html = urlopen("http://www.google.com/").read()
 print(html)

In general, it's recommended to use the latest python http clients - urllib3 or requests

pip3 install urllib3

pip3 install requests

If you're trying to read aa website content using its URL you can do it with requests:

import requests

response = requests.get("https://stackoverflow.com/")
print(response.text)

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