【问题标题】:parse src link from iframe response received from a post request从从发布请求收到的 iframe 响应中解析 src 链接
【发布时间】:2019-05-19 06:20:59
【问题描述】:

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

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.x parsing beautifulsoup


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:
      html_doc = select_req.text
      soup = BeautifulSoup(html_doc, 'html.parser')
      link = soup.find('iframe').get('src')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-29
        • 1970-01-01
        • 2014-03-22
        • 2013-05-10
        • 1970-01-01
        相关资源
        最近更新 更多