首页 > 解决方案 > 从从发布请求收到的 iframe 响应中解析 src 链接

问题描述

我像这样在python中使用数据发出发布请求

select_req = req.post('https://www.example.com/payment/', data=data)
print(select_req.text)

这输出

<iframe class="paymentFrame" src="https://www.google.com/hpp/pay.shtml" width="100%" height="400"  scrolling="yes" frameborder="no"></iframe>

我想解析 src 链接并将其保存到 parsed_link

print(parsed_link)

我希望这个输出 https://www.google.com/hpp/pay.shtml

标签: python-3.xparsingbeautifulsoup

解决方案


html_doc = select_req.text
soup = BeautifulSoup(html_doc, 'html.parser')
link = soup.find('iframe').get('src')

推荐阅读