如果你的有要使用Selenium進行導航,比如在JavaScript網站上,它會建議獲取頁面源並使用HTML解析器來提取你想要的數據。
BeautifulSoup是解析器的絕佳選擇。例如:
html = driver.page_source
soup = BeautifulSoup(html)
# Get *all* 'p' tags with the specified class attribute.
p_tags = soup.findAll('p',{'class':'market_value'})
for p in p_tags:
print p.text
這應該打印到屏幕包含在<p>
標籤與類market_value
文本。但是,如果不知道確切的頁面源代碼,很難給出具體細節。
但是,如果你確定要嚴格硒使用,你可以找到這些元素:
# Get *all* 'p' tags with the specified class attribute.
elements = driver.find_elements_by_class_name('market_value')
for element in elements:
print element.text
# or
# Get a *single* 'p' tag with the specified class attribute.
element = driver.find_element_by_class_name('market_value')
print element.text
份額PLZ網頁的URL –
的網址是[鏈接] https://marketsworld.com – dvitt90