Skip to content

Instantly share code, notes, and snippets.

@PaburoTC
Last active May 1, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaburoTC/a259d56b11ac9063c0fb26182141d746 to your computer and use it in GitHub Desktop.
Save PaburoTC/a259d56b11ac9063c0fb26182141d746 to your computer and use it in GitHub Desktop.
def __scrap_tweets(self):
try:
sleep(2)
tweets = self.driver.find_elements_by_xpath("//article[@role=\"article\"]")
for tweet in tweets:
author = tweet.find_element_by_xpath(".//div[@dir=\"ltr\"]").text
text = tweet.find_element_by_xpath(".//div[@class=\"css-901oao r-hkyrab r-1qd0xha r-a023e6 r-16dba41 "
"r-ad9z0x r-bcqeeo r-bnwqim r-qvutc0\"]").text
data = tweet.find_elements_by_xpath(".//div[@class=\"css-1dbjc4n r-xoduu5 r-1udh08x\"]")
time = tweet.find_element_by_xpath(".//time").get_attribute("datetime")
comments = self.__format_data(data[0].text)
retweets = self.__format_data(data[1].text)
likes = self.__format_data(data[2].text)
tweet = Tweet(user=author, date=time, likes=likes, retweets=retweets, comments=comments, text=text)
tweet.add()
except:
self.__scroll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment