我正在尝试进行网络抓取并使用以下代码:
import mechanize
from bs4 import BeautifulSoup
url = "http://www.indianexpress.com/news/indian-actions-discriminating-against-us-exp/1131015/"
br = mechanize.Browser()
htmltext = br.open(url).read()
articletext = ""
soup = BeautifulSoup(htmltext)
for tag in soup.findAll('p'):
articletext += tag.contents[0]
print articletext
但我收到以下错误:
Traceback (most recent call last):
File "C:/Python27/crawler/express.py", line 15, in <module>
articletext += tag.contents[0]
TypeError: coercing to Unicode: need string or buffer, Tag found
有人可以帮我解决这个错误吗,我是 Python 编程的新手。