gpt4 book ai didi

python - 使用python导入url库但出现错误 "request"

转载 作者:行者123 更新时间:2023-12-01 08:26:30 25 4
gpt4 key购买 nike

我正在测试一些代码,但出现了一个奇怪的错误,而这个错误应该是相当简单的。我的代码如下,并且正在返回:

ImportError: No module named request

我的代码如下:

import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup

url = ('Enter- ')
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')

# retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
print(tag.get('href', None))

这次我做错了什么?我知道它在代码的第一行,但我对库真的很陌生,所以我假设我搞砸了一些非常基本的东西!

最佳答案

我相信您正在运行 python 2,而不是 python 3。

您可以通过在命令行或代码中运行 which python 来验证这一点:

import sys
print(sys.version_info)

关于python - 使用python导入url库但出现错误 "request",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54209567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com