-
Notifications
You must be signed in to change notification settings - Fork 698
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
scraped telegram posts having line breaks like the original post #687
base: master
Are you sure you want to change the base?
Changes from all commits
6546279
117cab7
70c1a1f
ed3d520
41aeff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ def _soup_to_items(self, soup, pageUrl, onlyUsername = False): | |
url = rawUrl.replace('//t.me/', '//t.me/s/') | ||
date = datetime.datetime.strptime(dateDiv.find('time', datetime = True)['datetime'].replace('-', '', 2).replace(':', ''), '%Y%m%dT%H%M%S%z') | ||
if (message := post.find('div', class_ = 'tgme_widget_message_text')): | ||
content = message.text | ||
content = self.get_post_text(message) | ||
outlinks = [] | ||
for link in post.find_all('a'): | ||
if any(x in link.parent.attrs.get('class', []) for x in ('tgme_widget_message_user', 'tgme_widget_message_author')): | ||
|
@@ -143,6 +143,14 @@ def get_items(self): | |
raise snscrape.base.ScraperException(f'Got status code {r.status_code}') | ||
soup = bs4.BeautifulSoup(r.text, 'lxml') | ||
|
||
@staticmethod | ||
def get_post_text(post) -> str: | ||
result = [] | ||
# Using the features of the BS4 module itself | ||
for s in post.stripped_strings: | ||
result.append(s) | ||
return '\n'.join(result) | ||
Comment on lines
+148
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified to |
||
|
||
def _get_entity(self): | ||
kwargs = {} | ||
# /channel has a more accurate member count and bigger profile picture | ||
|
@@ -200,4 +208,4 @@ def _cli_setup_parser(cls, subparser): | |
|
||
@classmethod | ||
def _cli_from_args(cls, args): | ||
return cls._cli_construct(args, args.channel) | ||
return cls._cli_construct(args, args.channel) | ||
Comment on lines
-203
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still an undesired whitespace change. There should be a LF at the end of a (text-ish) file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Looks like GitHub doesn't display this correctly on the PR page itself, only in the full diff: https://github.com/JustAnotherArchivist/snscrape/pull/687/files#diff-7f40c11448f92ed2f5d1764136d372d15faa3d4da0272813e88478c4d8870a09L203) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
message
, notpost
, to avoid confusion with the variable in_soup_to_items
. This should also not be public API. So_get_message_text(message)
.