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'
有关如何解决此问题的任何想法?提前谢谢。
答案 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
属性,它可能是前者而不是后者。