我想用BeautifulSoup解析python中的htmldiv。在
我的代码:
url = "http://german-bash.org/action/random"
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html)
for div in soup.findAll('div','zitat'):
output = div.find('span', 'quote_zeile').string
print(output)
我要把所有的斯潘都放在沙发上”zitat区“但这不管用
您只获取第一个这样的
<span>
。再次使用.findAll()
查找所有此类跨度:这会产生:
^{pr2}$请注意,我还告诉
BeautifulSoup
要使用什么编码,取自响应Content-Type
报头;这对这个页面很重要,因为没有它,beauthoulsoup就猜错了。在相关问题 更多 >
编程相关推荐