Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Remove hidden elements from tweet text #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion twitter_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ def gen_tweets(pages):
dot = "."
tweets = []
for tweet in html.find('.stream-item'):
text = tweet.find('.tweet-text')[0].full_text
tweet_text_elements = tweet.find('.tweet-text')
if not tweet_text_elements:
continue
text_container = tweet_text_elements[0]
for hidden_child in text_container.lxml.find_class('u-hidden'):
hidden_child.drop_tree()
text = text_container.full_text.strip()
tweetId = tweet.find(
'.js-permalink')[0].attrs['data-conversation-id']
time = datetime.fromtimestamp(
Expand Down