繁体   English   中英

无法从机械化导入浏览器

[英]unable to import browser from mechanize

我是第一次使用机械化。 如果我在python shell(解释器)中from mechanize import Browser的行from mechanize import Browser则不会出现任何错误,但是当作为.py文件的一部分运行相同的代码时,会出现以下错误:

Traceback (most recent call last):
  File "/home/namit/Codes/BS4/mechanize.py", line 1, in <module>
    import mechanize
  File "/home/namit/Codes/BS4/mechanize.py", line 4, in <module>
    mech = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'

从mechanize.py更改文件名。 Python将文件导入为模块,而不是导入机械化库。

重命名您的文件名,而不是mechanize.py

提供与导入的模块相同的文件名会导致导入文件而不是预期的模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM