2016-11-20 12 views
0

は、これはこれは私が別のURLを試してみましたpowersehll

============== 
Traceback (most recent call last): 
File "crawlertest.py", line 9, in <module> 
soup = beautifulsoup(request) 
NameError: name 'beautifulsoup' is not defined 
============== 

からのエラー情報である私のコード powershellがなぜ私に名前の誤りを記録するのですか?

============== 
import urllib2 
from bs4 import BeautifulSoup 
url = 'https://www.crummy.com/software' 
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)' 
headers = {'User-Agent' : user_agent} 
request = urllib2.Request(url,headers = headers) 
response = urllib2.urlopen(request) 
content = response.read() 
soup = beautifulsoup(request) 
print soup.body#get the body element 
============== 

ですが、エラーが依然として存在します。 help

+0

'print soup.bdoy'を' print soup.body'に変更してください。 –

答えて

1

これはPowerShellではなく、Pythonスクリプトです。

Pythonは名前の大文字と小文字を区別します。

コードはBeautifulSoupをインポートし、beautifulsoupを使用しました。

import urllib2 
from bs4 import BeautifulSoup # <--- 
url = 'https://www.crummy.com/software' 
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)' 
headers = {'User-Agent' : user_agent} 
request = urllib2.Request(url,headers = headers) 
response = urllib2.urlopen(request) 
content = response.read() 
soup = BeautifulSoup(request) # <--- FIXED to match case 
print soup.body # <--- FIXED a typo 
+0

はい、それは今、あなたの助けに感謝します – Michael

関連する問題