Ubuntu 24.04.2 LTS中Python导入urllib模块报错求助
问题修复:urllib模块导入及调用错误
你的代码里存在两处明显拼写错误,这是导致报错的直接原因:
- 第5行模块名拼写错误:
ulrllib.request→ 正确应为urllib.request - 第8行方法名拼写错误:
urllib.request.ulrlopen→ 正确应为urllib.request.urlopen
另外,导入urllib后可直接使用urllib.request,单独导入urllib.request并非必须,但修正拼写后也能正常运行。
修正后的完整代码:
# Linkedin Learning Python for Data Science and Machine Learning Essential Training Part 1 from bs4 import BeautifulSoup import urllib import urllib.request import re with urllib.request.urlopen('http://raw.githubusercontent.com/BigDataGal/Data-Mania-Demos/master/IoT-2018.html') as response: html = response.read() soup = BeautifulSoup(html, 'html.parser') print(type(soup))
运行修正后的代码,即可正常完成模块导入、网页内容请求及后续HTML解析。
内容的提问来源于stack exchange,提问作者Mohlatlego Matsapola
相关产品推荐
相关产品推荐

