'模块'对象没有属性' get'?

时间:2015-11-02 04:04:11

标签: get python-3.4

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'

有关如何解决此问题的任何想法?提前谢谢。

1 个答案:

答案 0 :(得分:2)

您从 Scanner s=new Scanner(System.in); System.out.println("Anota una Frase: "); String str=s.nextLine(); int i = 0; while(i<=str.length()) { String str2 = str.substring(0,i); System.out.println(str2); i++; } 导入了request,但urllib没有urllib.request方法。我想您要导入get模块并使用requests代替requests.get。或者您要将request.get替换为get。考虑到您在下一行引用urlopen属性,它可能是前者而不是后者。