==============
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
==============
==============
Traceback (most recent call last):
File "crawlertest.py", line 9, in <module>
soup = beautifulsoup(request)
NameError: name 'beautifulsoup' is not defined
==============
我尝试了不同的网址,但错误仍然存在。帮助
答案 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