【发布时间】:2021-10-07 01:54:35
【问题描述】:
您好,我在控制台上打印 div 类文本时遇到问题...
这是我的代码:
import os
import time
from selenium import webdriver
from pyvirtualdisplay import Display
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
lol = input("Click to print div class text on console...")
driver = webdriver.Firefox()
driver.get("<any link to verification code")
verification_code = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.XPATH, "/html/body/table/tbody/tr/td/table/tbody/tr[4]/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]")))
print(verification_code)
但我得到了这个:
这是html代码:
<td style="padding:10px;color:#565a5c;font-size:32px;font-weight:500;text-align:center;padding-bottom:25px;">629107</td>
所以我需要在控制台上打印 629107 代码。
这是完整的html代码:
问题 2:
我有这个代码:
verification_code = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.XPATH, "/html/body/table/tbody/tr/td/table/tbody/tr[4]/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]")))
我需要在输入类上写 629107 代码。
这是输入类的 xpath:
/html/body/div[1]/section/main/div/div/div[1]/div[2]/form/div/div[1]/input
我该怎么做?
【问题讨论】:
标签: python html selenium selenium-webdriver