擅长:python、mysql、java
<p>在对列进行排序之前,导航网站时不会出现表类<code>wikitable sortable jquery-tablesorter</code>。通过使用table类<code>wikitable sortable</code>,我只获得了一个表。在</p>
<pre><code>import requests
from bs4 import BeautifulSoup
res = requests.get("https://en.wikipedia.org/wiki/Comparison_of_Intel_processors")
soup = BeautifulSoup(res.content, "html.parser")
tables = soup.find_all("table", class_="wikitable sortable")
print(len(tables))
</code></pre>
<p>注意事项:</p>
<ul>
<li>我在您的示例中使用了<code>class_=</code>而不是字典,因为<a href="http://web.stanford.edu/~zlotnick/TextAsData/Web_Scraping_with_Beautiful_Soup.html" rel="nofollow noreferrer">standford.edu tutorial on Beautiful Soup</a>。在</li>
<li>在<code>BeautifulSoup</code>类中定义了一个名为<code>html.parser</code>的解析器,因此代码可以按照打印的警告在不同的环境下工作。在</li>
</ul>