視頻版教程:一天掌握python爬蟲【基礎(chǔ)篇】 涵蓋 requests、beautifulsoup、selenium
主要text屬性和三個(gè)方法get_attribute(),get_property(),get_dom_attribute()
text屬性獲取元素的文本信息;
get_attribute(),get_property(),get_dom_attribute()三個(gè)方法都是獲取元素的屬性值
區(qū)別是property是DOM中的屬性,是JavaScript里的對(duì)象;
attribute是HTML標(biāo)簽上的屬性,
dom_attribute則只能是HTML標(biāo)簽規(guī)范定義的屬性(自定義的屬性獲取不到)。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-741728.html
我們一般開發(fā)用的是get_attribute()方法。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-741728.html
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
url = "http://www.java1234.com/"
browser.get(url)
time.sleep(2)
input = browser.find_element(By.ID, "time")
print(input.text)
print(input.get_attribute('id'))
print(input.get_property('id'))
print(input.get_dom_attribute('id'))
print(input.get_attribute('class'))
print(input.get_property('class'))
print(input.get_dom_attribute('class'))
到了這里,關(guān)于Python selenium獲取元素信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!