擅长:python、mysql、java
<p>您可以找到所有的<code>tr</code>元素,对它们进行迭代,然后对内部的<code>td</code>元素进行上下文特定的搜索,得到第一个和第三个:</p>
<pre><code>for tr in soup.find_all('tr'):
cells = tr.find_all('td')
if len(cells) < 3:
continue # safety pillow
link = cells[0].a['href'] # assuming every first td has an "a" element
data = cells[2].get_text()
print(link, data)
</code></pre>
<p>另外,根据您在HTML解析中要完成的工作,我通常发现<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_html.html" rel="nofollow">^{<cd3>}</a>是将HTML表解析为<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow">dataframes</a>并处理之后的数据帧的一种非常方便的方法,这是非常方便的数据结构。在</p>