You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 04:22:06