python怎么从一段字符串中获取想要的字符串?

从下面一段文本中获取“6”,就是我箭头指出来的这个,这个6它是会变的。
但是“你好”这两个字不会变,求多种方法,感谢万分

img

我的想法:获取href,再由正则获取&np=xxx


from bs4 import BeautifulSoup
import re

m = re.compile(r"(pn=)(\d+)")

string = """ 
<a href="f/like/mylike/?&pn=6">你好</a> 
<a href="f/like/mylike/?&pn=18">你好吗</a> 
<a href="f/like/mylike/?&pn=22">你好我也好</a> 
"""

soup = BeautifulSoup(string, "lxml")

for a in soup.find_all("a"):

    if "你好" in a.string:
        try:
            print(a.string, m.search(a['href']).group(2))

        except Exception as e:
            print(e)

结果:
你好 6
你好吗 18
你好我也好 22