-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.python
More file actions
45 lines (40 loc) · 1.75 KB
/
tempCodeRunnerFile.python
File metadata and controls
45 lines (40 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import re
import csv
from getpass import getpass
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from msedge.selenium_tools import Edge, EdgeOptions
def get_tweet_data(card):
"""Extract data from tweet card"""
username = card.find_element_by_xpath('.//span').text
try:
handle = card.find_element_by_xpath('.//span[contains(text(), "@")]').text
except NoSuchElementException:
return
try:
postdate = card.find_element_by_xpath('.//time').get_attribute('datetime')
except NoSuchElementException:
return
comment = card.find_element_by_xpath('.//div[2]/div[2]/div[1]').text
responding = card.find_element_by_xpath('.//div[2]/div[2]/div[2]').text
text = comment + responding
reply_cnt = card.find_element_by_xpath('.//div[@data-testid="reply"]').text
retweet_cnt = card.find_element_by_xpath('.//div[@data-testid="retweet"]').text
like_cnt = card.find_element_by_xpath('.//div[@data-testid="like"]').text
# get a string of all emojis contained in the tweet
"""Emojis are stored as images... so I convert the filename, which is stored as unicode, into
the emoji character."""
emoji_tags = card.find_elements_by_xpath('.//img[contains(@src, "emoji")]')
emoji_list = []
for tag in emoji_tags:
filename = tag.get_attribute('src')
try:
emoji = chr(int(re.search(r'svg\/([a-z0-9]+)\.svg', filename).group(1), base=16))
except AttributeError:
continue
if emoji:
emoji_list.append(emoji)
emojis = ' '.join(emoji_list)
tweet = (username, handle, postdate, text, emojis, reply_cnt, retweet_cnt, like_cnt)
return tweet