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

[poipiku] fix extraction for a different warning button style #3460

Merged
merged 1 commit into from
Jan 4, 2023

Conversation

the-blank-x
Copy link
Contributor

No description provided.

@@ -59,7 +60,7 @@ def items(self):
"//img.", "//img-org.", 1)
yield Message.Url, url, text.nameext_from_url(url, post)

if not extr('> show all', '<'):
if not re.search(r">\s*show all[\s\S]+?<", page):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not re.search(r">\s*show all[\s\S]+?<", page):
if not extr(' show all(+', '<'):

No need for regex. Updating the searched string to this seems to work for both old and new "show all" buttons.

And regarding regular expressions in general: You should pre-compile them and, if possible, use a reference to the method that gets used.

    search_show_all = re.compile(r">\s*show all[\s\S]+?<").search
...
            if not search_show_all(page):

[\s\S]

Isn't this the same as ., i.e. it matches everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same as ., i.e. it matches everything?

No,

>>> print(re.search(r'te.*st', 'te \n st'))
None
>>> print(re.search(r'te[\s\S]*st', 'te \n st'))
<re.Match object; span=(0, 7), match='te \n st'>

@mikf mikf merged commit 07ed3a1 into mikf:master Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants