[英]driver.find_elements_by_xpath('//div[@data-testid="tweet"]') gives No Output
I am trying to scrape tweets using twitter scraper I have tried a lot of solutions but it gives out empty list.我正在尝试使用 twitter 刮板刮推推文我尝试了很多解决方案,但它给出了空列表。
driver.find_elements_by_xpath('//div[@data-testid="tweet"]')
Whole chunk:整块:
cards = driver.find_elements_by_xpath('//div[@data-testid="tweet"]')
if len(cards) > 0:
card = cards[0]
else:
raise NoSuchElementException('No cards were found')
error
NoSuchElementException Traceback (most recent call last)
/tmp/ipykernel_18368/2095008957.py in <module>
3 card = cards[0]
4 else:
----> 5 raise NoSuchElementException('No cards were found')
NoSuchElementException: Message: No cards were found
(It's same as that in twitter scraper github repository: https://github.com/israel-dryer/Twitter-Scraper ) (与twitter刮板github仓库中的相同: https://github.com/israel-dryer/Twitter-Scraper )
You try to select the tweets in element <div>
but it is in an <article>
您尝试 select 元素
<div>
中的推文,但它位于<article>
Page need some time to load so wait until first tweet or somthing else is located first and then select more specific with article
:页面需要一些时间来加载,所以等到第一条推文或其他东西首先被定位,然后 select 更具体的
article
:
if WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//article[@data-testid="tweet"]'))):
for e in driver.find_elements(By.XPATH, '//article[@data-testid="tweet"]'):
print(e.text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.