【发布时间】:2015-12-03 07:12:43
【问题描述】:
我正在使用 beautifulsoup 进行网页抓取。该网页有以下来源:
<td>\n<a href="http://aaa.com">Charles</a>\r\n (hello)\r\n </td>,
<td>\n<a href="http://bbb.com">Diane</a>\r\n (hi)\r\n </td>,
<td>\n<a href="http://ccc.com">Kevin</a>\r\n (how are you doing)\r\n </td>
我使用以下代码打印两个值。它们工作得很好。
for item in soup.find_all("td"):
print item.find('a').text
print item.find('a').next_sibling
问题是当我将输出保存在 csv 文件中时,第二列没有任何值。出现是因为有很多空白。有什么建议吗?提前致谢。
【问题讨论】:
标签: python python-2.7 beautifulsoup html-parsing