import requests
import re

txt=\'<a href=”https://www.vgirls.com/13404.html” class=”list-title text-md h-2x” target=”_blank”>想把夏日的阳光寄给冬日的你</a>\’
urla=re.findall(\'<a href=”(.*?)” class=”list-title text-md h-2x” target=”_blank”>.*?</a>\’,txt)
for i in urla:
print(i)
urlb=re.findall(\'<a href=”.*?” class=”list-title text-md h-2x” target=”_blank”>(.*?)</a>\’,txt)
for i in urlb:
print(i)
结果:

https://www.vgirls.com/13404.html
想把夏日的阳光寄给冬日的你

总结:

1。根据网页源代码找到关键位置,主要分析相关同一级别的源代码的共同点

2。找到关键如txt的内容,复制下来
3。粘贴到空白处:urla=re.findall(\’   \’,txt)
4.需要选择出来的部分去掉改成 (.*?);不想选择但内容又变化的去掉改成  .?*,一定不能加括号

5。所以第一个只提取超级连接的地址;第二个只提取“标签A中的文字”

版权声明:本文为xkdn原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xkdn/p/12243681.html