解析来自发布请求的iframe响应中的src链接

时间:2019-05-19 06:21:00

标签: python-3.x parsing beautifulsoup

我用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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我希望CSS类选择器是更快的方法

soup = BeautifulSoup(select_req.text, 'html.parser')
parsed_link = soup.select_one('.paymentFrame')['src']