[英]Unable to locate element in selenium when xpath is there
I am trying to scrape the text of this linked in post: https://www.linkedin.com/feed/update/urn:li:activity:6761903191849230336/?updateEntityUrn=urn%3Ali%3Afs_feedUpdate%3A%28V2%2Curn%3Ali%3Aactivity%3A6761903191849230336%29我正在尝试在帖子中抓取此链接的文本: https://www.linkedin.com/feed/update/urn:li:activity:6761903191849230336/?updateEntityUrn=urn%3Ali%3Afs_feedUpdate%3A%28V2%2Curn% 3Ali%3Aactivity%3A6761903191849230336%29
my_url = 'https://www.linkedin.com/feed/update/urn:li:activity:6761903191849230336/?updateEntityUrn=urn%3Ali%3Afs_feedUpdate%3A%28V2%2Curn%3Ali%3Aactivity%3A6761903191849230336%29'
driver = webdriver.Chrome(r'C:\Users\Main\Documents\M&Saatchi\chromedriver')
driver.get(my_url)
sleep(5)
####MAIN PROGRAM#### - Page 1
source = soup(driver.page_source)
test = driver.find_element_by_xpath('//span[@class="break-words"]')
Currently I get:目前我得到:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//span[@class="break-words"]"}
(Session info: chrome=88.0.4324.182)
I know this XPath exists using inspect element (see below)我知道这个 XPath 存在使用检查元素(见下文)
Couldn't find the xpath for span class="break-words" inside Selenium but try this one.在 Selenium 中找不到 span class="break-words" 的 xpath 但试试这个。
wait = WebDriverWait(driver, 30)
driver.get('https://www.linkedin.com/feed/update/urn:li:activity:6761903191849230336/?updateEntityUrn=urn%3Ali%3Afs_feedUpdate%3A%28V2%2Curn%3Ali%3Aactivity%3A6761903191849230336%29')
elem=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"p.share-update-card__update-text")))
print(elem.text)
Import进口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Outputs输出
Today welcome Natassia Badenhorst to the Razor team as a Group Account Director. Tash has been with us for a while as a freelancer but today we get to make her a permanent member of the team and we couldn’t be happier. #powerfulconversations M&C Saatchi Group South Africa
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.