我正在尝试运行以下代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(options=options)
driver.get('https://theunderminejournal.com/#eu/draenor/battlepet/1155')
time.sleep(20) #bypass cloudflare
price = driver.find_element_by_xpath('//*[@id="battlepet-page"]/div[1]/table/tr[3]/td/span')
print (price)
所以我可以从页面上刮下“当前价格”。但是这个xpath位置不会返回文本值(我最后也尝试了“text”varriant,但没有成功。你知道吗
提前感谢您的回复
首先,使用WebdriverWait来等待元素而不是休眠。你知道吗
第二,你的定位器没有找到元素。你知道吗
试试这个
要使用wait import,请执行以下操作:
在获取文本之前,应该等待元素的可见性。在下面的示例中选中
WebDriverWait
:要从webpage中获取当前价格的值,需要为
visibility_of_element_located()
引入WebDriverWait,并且可以使用以下Locator Strategies之一:使用
CSS_SELECTOR
:使用
XPATH
:注意:必须添加以下导入:
相关问题 更多 >
编程相关推荐