使用python正则式提取div id=J_ip_historypspan class=date2023-04-02-----2023-04-05spana href=1562451343 target=_blank1562451343apdiv内的IP位置
可以使用以下正则表达式来提取IP位置:
import re
html = '<div id="J_ip_history">\n<p>\n<span class="date">2023-04-02-----2023-04-05</span>\n<a href="/156.245.13.43/" target="_blank">156.245.13.43</a>\n</p>\n</div>'
ip_pattern = re.compile('<div id="J_ip_history">.*?<a href="/(.*?)/" target="_blank">', re.S)
result = ip_pattern.search(html)
if result:
ip = result.group(1)
print(ip)
else:
print("No IP found.")
输出结果:
156.245.13.43
原文地址: https://www.cveoy.top/t/topic/bzay 著作权归作者所有。请勿转载和采集!