我似乎对beautifulsoup存在问题,无论我搜索什么,它都不会返回任何内容。例如:
from BeautifulSoup import BeautifulSoup
import urllib2
url="http://www.google.com"
html=urllib2.urlopen(url).read()
print type(html)
soup= BeautifulSoup(html)
soup.find_all('div')
返回:
C:\Users\Alexis\Desktop>ipython scrape.py
<type 'str'>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
C:\Users\Alexis\Desktop\scrape.py in <module>()
7 print type(html)
8 soup= BeautifulSoup(html)
----> 9 soup.find_all('div')
10
11
TypeError: 'NoneType' object is not callable
我尝试升级到最新版本。没有变化。
答案 0 :(得分:0)
将导入行更改为此以使用BeautifulSoup4:
div
将程序的最后一行更改为此内容以打印出for div in soup.find_all('div'):
print('here comes another div')
print(div)
s:
word = 'lake1!'
new_word = ''
for char in word:
if char.isalpha():
new_word += char