吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1173|回复: 10
收起左侧

[求助] python正则表达式提取标签属性与链接?

[复制链接]
double07 发表于 2021-4-28 21:56
[Python] 纯文本查看 复制代码
<tr class="sticky_normal">
<td class="rowfollow nowrap" valign="middle" style='padding: 0'><a href="?cat=432"><img src="pic/cattrans.gif" alt="网红/Blu-Ray Uncensored" title="网红/Blu-Ray Uncensored" style="background-image: url(pic/category/chd/scenetorrents/cht/uenbd.png);" /></a></td>
<td class="torrenttr" width="100%" align="left"><table class="torrentname" width="100%"><tr class="sticky_normal"><td class="torrentimg"><a title="重庆渝中区洪涯洞打卡点" href="details.php?id=482015&hit=1"><img alt="torrent thumbnail" src="https://img.cqgov.org/images/2021/04/28/cbc2118b6f2466e5f954567a54c937a3.jpg"></a></td><td class="embedded"><img class="sticky" src="pic/trans.gif" alt="Sticky" title="置頂" /> <a title="重庆渝中区洪涯洞打卡点" href="details.php?id=482015&hit=1"><b>重庆渝中区洪涯洞打卡点</b></a> <img class="pro_50pctdown" src="pic/trans.gif" alt="50%" title="50%" /> <img src="pic/trans.gif" class="label_sub" alt="中国" /><br />网红景点</td><td width="80" class="embedded" style="text-align: right; " valign="middle"><a href="download.php?id=482015&https=1"><img class="download" src="pic/trans.gif" style='padding-bottom: 2px;' alt="download" title="下载图片" /></a><a id="bookmark2"  href="javascript: bookmark(482015,2);" ><img class="delbookmark" src="pic/trans.gif" alt="Unbookmarked" title="收藏" /></a></td>
</tr></table></td><td class="rowfollow"><b><a href="details.php?id=482015&hit=1&cmtpage=1#startcomments" >4</a></b></td><td class="rowfollow nowrap"><span title="2021-04-28 03:08:22">18时<br />36分</span></td><td class="rowfollow">19.22<br />GB</td><td class="rowfollow" align="center"><b><a href="details.php?id=482015&hit=1&dllist=1#seeders">82</a></b></td>
<td class="rowfollow"><b><a href="details.php?id=482015&hit=1&dllist=1#leechers">11</a></b></td>
<td class="rowfollow"><a href="viewsnatches.php?id=482015"><b>122</b></a></td>
<td class="rowfollow" style="font-weight: bold">--</td><td class="rowfollow"><i>匿名</i></td>




请问把<a>标签”重庆渝中区洪涯洞打卡点“及herf中的链接用正则怎样提取出来?

按这样写,但提不出来:<a.*?title="(.*?)"href="(.*?)".*?><b>.*?</b></a>

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

cmy2019 发表于 2021-4-28 22:05
你写的正则缺个空格,就在href前边。。。
fanvalen 发表于 2021-4-28 22:08
[Asm] 纯文本查看 复制代码
<a title="(.*?)" href="(.*?)"><img[\s\S]+?<b>.*?</b></a>
Airey 发表于 2021-4-28 22:10
本帖最后由 Airey 于 2021-4-28 22:13 编辑

for k in soup.find_all('a'):
    print(k['href'])#查a标签的href值
    k.get('href')
fanvalen 发表于 2021-4-28 22:15
一是空格让它存在就好,
二是href="(.*?)"之后的.*?遇到一个>就终止了后面接<b>.*?</b></a>(>后面没有接b标签), 因为到<b>.*?</b></a>不是连续的所以匹配不到

免费评分

参与人数 1吾爱币 +1 收起 理由
double07 + 1 我很赞同!

查看全部评分

 楼主| double07 发表于 2021-4-28 22:30
本帖最后由 double07 于 2021-4-28 22:33 编辑

刚开始学,还在摸索中,按目前的表达式,提取出来是段代码,而且有重复的值。最终目标想提取出”重庆渝中区洪涯洞打卡点“及details.php?id=482015&hit=1这两个字段且不重复,正则怎样实现?
kai-memory 发表于 2021-4-29 02:06
考虑用xpath?
 楼主| double07 发表于 2021-4-29 08:46

xpath没法用,现学的正则
头像被屏蔽
百千三昧 发表于 2021-4-29 13:02
提示: 作者被禁止或删除 内容自动屏蔽
头像被屏蔽
百千三昧 发表于 2021-4-29 13:13
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-16 12:18

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表