Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parsing of images #221

Open
wants to merge 1 commit 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
13 changes: 10 additions & 3 deletions twitterscraper/tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@generate_ordering('timestamp', 'id', 'text', 'user', 'replies', 'retweets', 'likes')
class Tweet:
def __init__(self, username, fullname, user_id, tweet_id, tweet_url, timestamp, timestamp_epochs, replies, retweets,
likes, is_retweet, retweeter_username, retweeter_userid, retweet_id,text, html):
likes, is_retweet, retweeter_username, retweeter_userid, retweet_id,text, html, picture_url):
self.username = username.strip('\@')
self.fullname = fullname
self.user_id = user_id
Expand All @@ -24,6 +24,7 @@ def __init__(self, username, fullname, user_id, tweet_id, tweet_url, timestamp,
self.retweet_id = retweet_id
self.text = text
self.html = html
self.picture = picture_url

@classmethod
def from_soup(cls, tweet):
Expand Down Expand Up @@ -57,9 +58,15 @@ def from_soup(cls, tweet):
'span', 'ProfileTweet-action--favorite u-hiddenVisually').find(
'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0')
html = str(tweet.find('p', 'tweet-text')) or ""


img = tweet.find('div', 'js-adaptive-photo')
if img:
picture_url = img["data-image-url"]
else:
picture_url = ''

c = cls(username, fullname, user_id, tweet_id, tweet_url, timestamp, timestamp_epochs, replies, retweets, likes,
is_retweet, retweeter_username, retweeter_userid, retweet_id,text, html)
is_retweet, retweeter_username, retweeter_userid, retweet_id,text, html, picture_url)
return c

@classmethod
Expand Down