我试着按元素类向下滚动。我需要在twitter.com中滚动推特
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get('http://twitter.com/elonmusk')
sleep(5)
while True:
html = driver.find_element_by_class_name('css-901oao r-1fmj7o5 r-1qd0xha r-a023e6 r-16dba41 r-rjixqe r-bcqeeo r-bnwqim r-qvutc0')
html.send_keys(Keys.END)我有错误:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .css-901oao r-1fmj7o5 r-1qd0xha r-a023e6 r-16dba41 r-rjixqe r-bcqeeo r-bnwqim r-qvutc0发布于 2021-07-05 10:07:40
该类名在代码中有空格,class_name不使用空格,请尝试下面的xpath:
//div[@data-testid='tweet']你可以用代码写成这样:
counter = 1
while True:
html = driver.find_element_by_xpath(f"(//div[@data-testid='tweet'])[{counter}]")
counter = counter + 1
html.send_keys(Keys.END)https://stackoverflow.com/questions/68254180
复制相似问题