从这个Python代码中,

...
resp = logout_session.get(logout_url, headers=headers, verify=False, allow_redirects=False)
soup = BeautifulSoup(resp.content, "html.parser")
print(soup.prettify())

我能够进行API调用,响应内容如下:

<!DOCTYPE html>
<html>
 <head>...</head>
 <body>
  <div class="container">
   <div class="title logo" id="header">
    <img alt="" id="business-logo-login" src="/customviews/image/business_logo:f0a067275aba3c71c62cffa2f50ac69c/"/>
   </div>
   <div class="input-group alert alert-success text-center" id="title" role="alert">
    Successfully signed out
   </div>
   <div class="input-group alert text-center">
    <a href="/saml-idp/portal/">
     Login again
    </a>
   </div>
   <div>
    <p>
     You will be redirected to https://idpftc.business.com/saml/Gy736KPK3v1aWDPECRZKAn/proxy_logout/ after 5 seconds ...
    </p>
    <script language="javascript" nonce="">
     window.onload = window.setTimeout(function() {
    window.location.replace("https://idpftc.business.com/saml/Gy736KPK3v1aWDPECRZKAn/proxy_logout/?SAMLResponse=3VjJkuNIjv2VtKijLJObJIphlWnGfd93Xtoo7vsukvr6ZkRU");}, 5000);
    </script>
   </div>
  </div>
 </body>
</html>

现在我想提取html链接:

https://idpftc.business.com/saml/Gy736KPK3v1aWDPECRZKAn/proxy_logout/?SAMLResponse=3VjJkuNIjv2VtKijLJObJIphlWnGfd93Xtoo7vsukvr6ZkRU 

从这篇内容中,有谁知道如何用PYTHON来做到这一点?

推荐答案

试着:

import re

# resp = requests.get(...)

url = re.search(r'window\.location\.replace\("([^"]+)', resp.text).group(1)
print(url)

打印:

https://idpftc.business.com/saml/Gy736KPK3v1aWDPECRZKAn/proxy_logout/?SAMLResponse=3VjJkuNIjv2VtKijLJObJIphlWnGfd93Xtoo7vsukvr6ZkRU

Python相关问答推荐

韦尔福德方差与Numpy方差不同

如何检测背景有噪的图像中的正方形

'discord.ext. commanders.cog没有属性监听器'

Python中的嵌套Ruby哈希

Excel图表-使用openpyxl更改水平轴与Y轴相交的位置(Python)

将输入管道传输到正在运行的Python脚本中

如何调整QscrollArea以正确显示内部正在变化的Qgridlayout?

实现自定义QWidgets作为QTimeEdit的弹出窗口

无法连接到Keycloat服务器

如何使用SentenceTransformers创建矢量嵌入?

合并帧,但不按合并键排序

Django admin Csrf令牌未设置

如何在两列上groupBy,并使用pyspark计算每个分组列的平均总价值

如果包含特定值,则筛选Groupby

如何在Gekko中使用分层条件约束

如何在Airflow执行日期中保留日期并将时间转换为00:00

按条件添加小计列

极点替换值大于组内另一个极点数据帧的最大值

将数字数组添加到Pandas DataFrame的单元格依赖于初始化

Pandas:根据相邻行之间的差异过滤数据帧