python正则匹配
有一个js字符串,我想匹配其中<td align="center" id="instid1_Ag(T+D)">Ag(T+D)</td>
<td align="center" id="last_Ag(T+D)">3782.00</td>这里的Ag(T+D)和3782.00该怎么写正则啊
尝试了一下午还是摸不着头脑,谢谢大佬们不吝赐教
<HTML>
<body style="overflow:hidden;">
<div id="list" class="indexBlock" width="100%" >
<table id="resultTable" name="resultTable" width="100%" class="lst">
<tr style="height: 50px">
<th align="center">品种</th>
<th align="center">当前价</th>
<th align="center">涨跌</th>
<th align="center">涨跌幅</th>
<th align="center">成交量(手)</th>
<th align="center">开盘价</th>
<th align="center">昨收价</th>
<th align="center">最高价</th>
<th align="center">最低价</th>
<th align="center">操作</th>
</tr>
<tr style="height: 42px">
<td align="center" id="instid1_Ag(T+D)">Ag(T+D)</td>
<td align="center" id="last_Ag(T+D)">3782.00</td>
<td id="updown_Ag(T+D)" align="center" ><img src="/icbc/newperbank/images/fup.png" border="0" width="13" height="15"></td>
<td align="center" id="updownrtdis_Ag(T+D)">+0.2917%</td>
<td align="center" id="volume_Ag(T+D)">9339924</td>
<td align="center" id="open_Ag(T+D)">3785.00</td>
<td align="center" id="lstclose_Ag(T+D)">3771.00</td>
<td align="center" id="high_Ag(T+D)">3813.00</td>
<td align="center" id="low_Ag(T+D)">3740.00</td>
<td align="center" class="icbc_stock">
<a href="javascript:AtomSerivceSubmit('PBL201333','080020000219|Ag(T+D)|1');"><img src="/icbc/newperbank/perbank3/images/gold_trade.png"></a>
</td>
</tr>
<tr style="height: 42px">
<td align="center" id="instid1_Au(T+D)">Au(T+D)</td>
<td align="center" id="last_Au(T+D)">383.06</td>
<td id="updown_Au(T+D)" align="center" ><img src="/icbc/newperbank/images/fup.png" border="0" width="13" height="15"></td>
<td align="center" id="updownrtdis_Au(T+D)">+0.5512%</td>
<td align="center" id="volume_Au(T+D)">77894</td>
<td align="center" id="open_Au(T+D)">381.49</td>
<td align="center" id="lstclose_Au(T+D)">380.69</td>
<td align="center" id="high_Au(T+D)">383.50</td>
<td align="center" id="low_Au(T+D)">380.60</td>
<td align="center" class="icbc_stock">
<a href="javascript:AtomSerivceSubmit('PBL201333','080020000218|Au(T+D)|1');"><img src="/icbc/newperbank/perbank3/images/gold_trade.png"></a>
</td>
</tr>
<td align="center" id="last_(.*?)">(.*?)</td>
可能是这样?
留给下一位解答
">(.+?)</td> import re
data='''
<tr style="height: 42px">
<td align="center" id="instid1_Ag(T+D)">Ag(T+D)</td>
<td align="center" id="last_Ag(T+D)">3782.00</td>
<td id="updown_Ag(T+D)" align="center" ><img src="/icbc/newperbank/images/fup.png" border="0" width="13" height="15"></td>
<td align="center" id="updownrtdis_Ag(T+D)">+0.2917%</td>
<td align="center" id="volume_Ag(T+D)">9339924</td>
<td align="center" id="open_Ag(T+D)">3785.00</td>
<td align="center" id="lstclose_Ag(T+D)">3771.00</td>
<td align="center" id="high_Ag(T+D)">3813.00</td>
<td align="center" id="low_Ag(T+D)">3740.00</td>
'''
pat=r"<td align=\"center\" id=\"(.*?)\">(.*?)</td>"
r=re.findall(pattern=pat,string=data)
print(r) 丶虚伪 发表于 2020-5-14 16:23
(.*?)
可能是这样?
留给下一位解答
这个是你的表达式的结果 import re
a='<td align="center" id="last_Ag(T+D)">3782.00</td>'
data=re.findall('id="last_(Ag\(T\+D\))">([\d]{1,}\.[\d]{1,})</td>',a)
print(data) fanvalen 发表于 2020-5-14 16:26
import re
data='''
老哥太感谢了,这都好几次帮我解答了,论坛的发展离不开你这样有能力,热心肠的坛友。 lntuer 发表于 2020-5-14 16:30
import re
a='3782.00'
data=re.findall('id="last_(Ag\(T\+D\))">([\d]{1,}\. ...
谢谢,匹配出来啦:handshake 神之名 发表于 2020-5-14 16:23
">(.+?)
刚好匹配出想要的,感谢您{:1_893:} lntuer 发表于 2020-5-14 16:30
import re
a='3782.00'
data=re.findall('id="last_(Ag\(T\+D\))">([\d]{1,}\. ...
谢啦,就是这样的{:1_921:}
页:
[1]
2