且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python:使用正则表达式在某些网站标签之间查找句子

更新时间:2023-02-21 14:11:46

如果你必须用正则表达式来做,试试这样的:

If you must do it with regular expressions, try something like this:

a = re.finditer('<a.+?question-hyperlink">(.+?)</a>', html)
for m in a: 
    print m.group(1)

仅供参考,此代码执行相同的操作,但方式更加健壮:

Just for the reference, this code does the same, but in a far more robust way:

doc = BeautifulSoup(html)
for a in doc.findAll('a', 'question-hyperlink'):
    print a.text