为什么powershell会注意到我的名字错误?

时间:2016-11-20 04:28:19

标签: python 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)
print soup.body#get the body element
==============

这是powersehll

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

我尝试了不同的网址,但错误仍然存​​在。帮助

1 个答案:

答案 0 :(得分: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