Python re - escape coincidental parentheses in regex pattern

十年热恋 提交于 2019-11-29 18:02:56
alecxe

You need to escape the parenthesis since they have a special meaning:

<a href="javascript:__doPostBack\('(.*?)','(.*?)'\)">
                             HERE^            HERE^

Note that, ideally, you should not be parsing HTML with regex (even though your pattern is quite specific and I don't think this is that bad). Instead, parse HTML with, say, BeautifulSoup, locate the a element, get the href attribute value and then extract the desired substrings with regex.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!