-
Notifications
You must be signed in to change notification settings - Fork 718
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?
scraped telegram posts having line breaks like the original post #687
Conversation
…r having line breaks in result
…elScraper._soup_to_items method
… - convert long lines to paragraphs
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.
Please revert the indentation and empty line changes, then I can review the other changes.
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.
The indentation is still wrong and the diff unreadable.
Please do a favor and check the code. |
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.
Thanks for the cleanup. The indentation of the new function is still incorrect though as it uses spaces, not tabs, so the code is a syntax error currently. Other things below.
return cls._cli_construct(args, args.channel) | ||
return cls._cli_construct(args, args.channel) |
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.
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 comment
The 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)
result = [] | ||
# Using the features of the BS4 module itself | ||
for s in post.stripped_strings: | ||
result.append(s) | ||
return '\n'.join(result) |
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.
This can be simplified to '\n'.join(post.stripped_strings)
, but it doesn't do the right thing anyway. It splits out links into separate lines, and it doesn't preserve multiple line breaks. A good test case for both is https://t.me/telegram/201. Looks like this might require explicitly replacing the <br>
tags.
@@ -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: |
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
, not post
, to avoid confusion with the variable in _soup_to_items
. This should also not be public API. So _get_message_text(message)
.
When I tested snscrape for Telegram channels, I recognized that the posts don't have line breaks. And this caused problem for my text analysis. So I created the static method "get_post_text()" for that.
I also did a little cleaning in file code which are as follows: