擅长:python、mysql、java
<p>要找到宽度最大的<em>td</em>,可以在从<em>find\u all</em>调用返回的<em>td</em>列表中使用<em>max</em>,将键设置为<code>key=lambda t: int(t["width"])</code>:</p>
<pre><code>soup = BeautifulSoup(page, 'html.parser')
cells = soup.find_all("td", width=True)
mx_td = max(cells, key=lambda t: int(t["width"]))
</code></pre>
<p><code>t["width"]</code>访问<em>属性</em>值,我们需要对结果调用<em>int</em>,否则值将被比较<a href="https://en.wikipedia.org/wiki/Lexicographical_order" rel="nofollow">lexicographically</a>,即{<cd3>}将为真。在</p>