我在 9 个月前尝试使用 selenium 访问,但总是出错。
def function1(nick_hraca):
driver = webdriver.Chrome()
base_url = "https://lichess.org/@/" + nick_hraca
driver.get(base_url)
driver.minimize_window()
#activity = driver.find_element(By.XPATH,'//*[@id="us_profile"]/div[2]/div/div/p[2]/time')
#print(activity.get_attribute(""))
activity = driver.find_element(By.CLASS_NAME,"time")
print(activity.get_attribute("set"))
games = driver.find_element(By.XPATH,'//*[@id="main-wrap"]/main/div/div[5]/a[2]')
#print(activity.text)
print(games.text)
time.sleep(5)
driver.quit()
有人可以帮助我吗?
预先感谢我尝试过这个,但没用
#activity = driver.find_element(By.XPATH,'//*[@id="us_profile"]/div[2]/div/div/p[2]/time')
#print(activity.get_attribute("set"))
class = "time"
查找
driver.find_element(By.CLASS_NAME,"time")
。 但目标元素的属性是
class = "set"
。并且
9 months ago
是元素的文本。 您可以通过
.text
属性获得它。尝试
activity = driver.find_element(By.CLASS_NAME,"set")
print(activity.text)
或
activity = driver.find_element(By.XPATH,"//time")
print(activity.text)