擅长:python、mysql、java
<p>bs只获取第一个li元素。我不知道为什么。如果你想尝试使用lxml,这里有一个方法</p>
<pre><code>import lxml
from lxml import html
url = 'https://www.wlrk.com/attorney/hahn/'
res = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'})
tree = html.fromstring(res.content)
education = tree.xpath("//div[@class='attorney education']//li/a/text()")
print(education)
</code></pre>
<p>输出:</p>
<blockquote>
<p>['Carleton College', 'New York University School of Law']</p>
</blockquote>