擅长:python、mysql、java
<p>我通常用硒来配靓汤。Beautiful Soup是一个用于解析HTML和XML文档的Python包。</p>
<p>使用Beautiful Soup,您可以通过以下方式获得列表框中的项目数:</p>
<pre><code>from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.PhantomJS() # or webdriver.Firefox()
driver.get('http://some-website.com/some-page/')
html = driver.page_source.encode('utf-8')
b = BeautifulSoup(html, 'lxml')
items = b.find_all('p', attrs={'id':'ctl00_MainContent_accountItemsListBox'})
print(len(items))
</code></pre>
<p>我假设您要查找的DOM元素是一个段落(<code>p</code>标记),但是您可以用需要查找的任何元素替换它。</p>