【发布时间】:2015-10-11 19:56:38
【问题描述】:
这是代码和示例结果,我只希望表格的第一列忽略其余部分。 Stackoverflow 上有类似的问题,但没有帮助。
<tr>
<td>JOHNSON</td>
<td> 2,014,470 </td>
<td>0.81</td>
<td>2</td>
</tr>
我只想要 JOHNSON,因为它是第一个孩子。 我的python代码是:
import requests
from bs4 import BeautifulSoup
def find_raw():
url = 'http://names.mongabay.com/most_common_surnames.htm'
r = requests.get(url)
html = r.content
soup = BeautifulSoup(html)
for n in soup.find_all('tr'):
print n.text
find_raw()
我得到了什么:
SMITH 2,501,922 1.0061
JOHNSON 2,014,470 0.812
【问题讨论】:
-
您的问题并不完全清楚。如果你得到每个 tr 的第一个子 td,你想要第一个 column 而不是第一个 row。你能澄清一下吗?
-
已编辑。确实是专栏
标签: python beautifulsoup python-requests