我正在尝试从该站点提取随机生成的 ID 值。 但即使我组合这些
find_element
选项,我也无法提取这些 ID 值。
我应该使用什么选项来提取它?
<ul class="clear list01"><li><a href="#" name="lnkName">2cutecher</a></li><li><a href="#" name="lnkName">Aceog</a></li><li><a href="#" name="lnkName">Bushba</a></li><li><a href="#" name="lnkName">Catcheman</a></li><li><a href="#" name="lnkName">Contencewo</a></li><li><a href="#" name="lnkName">Cozyfoot</a></li><li><a href="#" name="lnkName">Desigoesi</a></li><li><a href="#" name="lnkName">FlashTa</a></li><li><a href="#" name="lnkName">Gamyopra</a></li><li><a href="#" name="lnkName">Grimazon</a></li><li><a href="#" name="lnkName">Idolin</a></li><li><a href="#" name="lnkName">Inetenli</a></li><li><a href="#" name="lnkName">Jiggyny</a></li><li><a href="#" name="lnkName">Kenjill</a></li><li><a href="#" name="lnkName">LuvFlirty</a></li><li><a href="#" name="lnkName">Metabre</a></li><li><a href="#" name="lnkName">MuraPira</a></li><li><a href="#" name="lnkName">Patepoi</a></li><li><a href="#" name="lnkName">Penhama</a></li><li><a href="#" name="lnkName">PlusAnguris</a></li><li><a href="#" name="lnkName">Rawcsto</a></li><li><a href="#" name="lnkName">Runen</a></li><li><a href="#" name="lnkName">SarenApril</a></li><li><a href="#" name="lnkName">Sexylo</a></li><li><a href="#" name="lnkName">Slashoest</a></li><li><a href="#" name="lnkName">ToughDressy</a></li><li><a href="#" name="lnkName">Tricar</a></li><li><a href="#" name="lnkName">Upforia</a></li><li><a href="#" name="lnkName">Uppertska</a></li><li><a href="#" name="lnkName">Wowro</a></li></ul>
driver.get('https://www.spinxo.com/')
spin_btn = driver.find_element(By.CLASS_NAME, 'spin')
spin_btn.click()
id_list = (driver.find_elements(By.NAME, 'lnkName'))
for id in range(len(id_list)):
print(id_list[id].text)
有两件事:
请参考以下代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://www.spinxo.com/')
driver.maximize_window()
driver.implicitly_wait(10)
# Below line will click on Consent button - Use this line if you get the Consent pop-up
driver.find_element(By.XPATH, "//p[text()='Consent']").click()
spin_btn = driver.find_element(By.CLASS_NAME, 'spin')
spin_btn.click()
id_list = driver.find_elements(By.NAME, 'lnkName')
for id in id_list:
print(id.text)
控制台输出:
2freethay
BabyZero
BagoYounger
Bellit
BraceLasting
CheerupSuru
CountryBlacken
Eirenga
Entelle
Heerer
Inedcity
Jungshoo
Katia
MelConfident
Mixedia
NumAmerica
Offshowan
Presbusi
PressMissing
Prodigyro
Selfcher
Skribitne
StroonsSunny
Strozvige
Tanyco
Tendreach
Tioniary
VamBe
WardZin
Xyloftwa
Process finished with exit code 0