'模块'对象没有属性'获取'?

中口广典
from urllib import request
from bs4 import BeautifulSoup
def trade_spider(max_pages):
page = 1
while page <= max_pages:
    x = 16958 + int(page)
    url = 'http://mery.jp/' + str(x)
    source_code = request.get(url)
    plain_text = source_code.text
    soup = BeautifulSoup(plain_text)
    print(soup)
    break

trade_spider(2)

当我尝试在Python3.4中运行上面的代码时,收到一条错误消息,内容如下:

File "web_crawler.py", line 15, in <module>
trade_spider(2)
File "web_crawler.py", line 9, in trade_spider
source_code = request.get(url)
AttributeError: 'module' object has no attribute 'get'

有想法该怎么解决这个吗?先感谢您。

安德鲁·Z

您是request导入urllib,但urllib.request没有get方法。我认为您想导入requests模块并requests.get代替request.get或者,或者您要替换geturlopen考虑到您.text在下一行中引用该属性,它可能是前者而不是后者。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python AttributeError:“模块”对象没有属性“获取”

AWS Lambda中的Python:“模块'请求'没有属性'获取'”

获取AttributeError:模块'mysql'在python中没有属性'connector'

模块“ selenium.webdriver”没有属性“获取”

从matplotlib和噪音获取'模块没有属性'

TensorFlow:'模块'对象没有属性'SessionRunHook'

AttributeError:“模块”对象没有属性“ TestCase”

AttributeError:“模块”对象没有属性“测试”

'模块'对象没有属性'isna'

AttributeError:“模块”对象没有属性“授权”

AttributeError:“模块”对象没有属性“计算”

AttributeError:“模块”对象没有属性“版本”

AttributeError:“模块”对象没有属性“ grd”

AttributeError:“模块”对象没有属性“打开”

AttributeError:“模块”对象没有属性“ mkdirs”

“模块”对象没有属性“ SummaryWriter”

pyFluidsynth'模块'对象没有属性'Synth'

AttributeError:“模块”对象没有属性“ cm”

AttributeError:“'模块'对象没有属性'ARRAY'”

AttributeError:“模块”对象没有属性“连接”

“模块”对象没有属性“ GeoSQLCompiler”

继承AttributeError:“模块”对象没有属性

numpy“模块”对象没有属性“堆栈”

“模块”对象没有属性“ TK”

AttributeError:'模块'对象没有属性'urlopen'

AttributeError:“模块”对象没有属性“ xxxx”

ssl“模块”对象没有属性“ SSLContext”

AttributeError:'模块'对象没有属性'utcnow'

AttributeError:“模块”对象没有属性“错误”