有没有一种方法可以使用请求和beautifulSoup访问iframe?蟒蛇

时间:2020-08-28 02:53:36

标签: python web-scraping beautifulsoup python-requests

我正在尝试使用请求和BeautifulSoup登录到经纪人网页,但是,大多数商品都位于我似乎无法访问的iframe中。

import requests
from bs4 import BeautifulSoup

r = requests.get('https://webtrader.icmarkets.com/')

print(r.text)

想访问iframe以发送我的凭据以登录到页面。我使用了硒,它可以工作,但在投入生产时仍不够稳定,当时它希望使用请求来查看这样做是否更有效。预先感谢您的帮助。

<html>
<head>
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>IC Markets WebTrader</title>
    <link rel="shortcut icon" type="image/x-icon" href="/wp-content/themes/boldy/images/favicon-1.ico">
    <meta name="description" content="IC Markets is the leading True ECN forex broker in Australia. We offer Forex, indices, commodities and CFD trading on spreads from 0.0 pips.">
    <meta name="keywords" content="icmarkets web trader">
    <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="/assets/fonts.css?ver=1.0">
    <link rel="stylesheet" href="/assets/css/font-awesome.min.css">
    <link rel="stylesheet" href="/assets/style.css?ver=1.3">
    <link rel="stylesheet" href="/assets/bootstrap.min.css">
</head>
<body>
<div id="wrapper">
    <div id="header">
        <div class="logo"></div>
        <div id="info-wrap" >
            <a href="https://secure.icmarkets.com" target="_blank" class="btn btn-red">CLIENT AREA</a>
            <ul id="info">
                <li>
                    <a href="https://secure.icmarkets.com/Finance/Deposit" target="_blank">
                        <span><i class="fa fa-money"></i></span>Deposit
                    </a>
                </li>
                <li>
                    <a href="javascript:void(0);" onclick="window.open('https://secure.livechatinc.com/licence/1605601/open_chat.cgi?groups=0','popUpWindow','height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');" class="livechat">
                        <span><i class="fa fa-comment"></i></span>Live Chat
                    </a>
                </li>
                <li>
                    <a href="http://blog.icmarkets.com" target="_blank">
                        <span><i class="fa fa-line-chart"></i></span>Market Analysis
                    </a>
                </li>
                <li>
                    <a href="https://www.icmarkets.com" target="_blank">
                      <span>  <font size="+2.5"><i class="fa fa-home"></i> </font></span>
                    </a>
                </li>
            </ul>
        </div>
    </div>

    <!--
    <iframe src="https://trade.mql5.com/trade?servers=ICMarkets-Demo%2cICMarkets-MT5%2cICMarkets-Demo01%2cICMarkets-Demo02%2cICMarkets-Demo03%2cICMarkets-Live01%2cICMarkets-Live02%2cICMarkets-Live03%2cICMarkets-Live04%2cICMarkets-Live05%2cICMarkets-Live06%2cICMarkets-Live07%2cICMarkets-Live08%2cICMarkets-Live09%2cICMarkets-Live10%2cICMarkets-Live11%2cICMarkets-Live12%2cICMarkets-Live14%2cICMarkets-Live15%2cICMarkets-Live16%2cICMarkets-Live17%2cICMarkets-Live18%2cICMarkets-Live19&trade_server=ICMarkets-Live01&demo_server=ICMarkets-Demo02&startup_mode=open_demo&lang=en" allowfullscreen="allowfullscreen" style="width: 100%; height: calc(100% - 60px); border: none"></iframe>
    -->

    <!-- Web Terminal Code Start -->
    <div id="webterminal"></div>
    <script type="text/javascript" src="https://trade.mql5.com/trade/widget.js"></script>
    <script type="text/javascript">
        new MetaTraderWebTerminal( "webterminal", {
            version: 4,
            servers: [
                'ICMarkets-MT5',
                'ICMarkets-Demo',
                'ICMarkets-Demo01',
                'ICMarkets-Demo02',
                'ICMarkets-Demo03',
                'ICMarkets-Demo04',
                'ICMarkets-Live01',
                'ICMarkets-Live02',
                'ICMarkets-Live03',
                'ICMarkets-Live04',
                'ICMarkets-Live05',
                'ICMarkets-Live06',
                'ICMarkets-Live07',
                'ICMarkets-Live08',
                'ICMarkets-Live09',
                'ICMarkets-Live10',
                'ICMarkets-Live11',
                'ICMarkets-Live12',
                'ICMarkets-Live13',
                'ICMarkets-Live14',
                'ICMarkets-Live15',
                'ICMarkets-Live16',
                'ICMarkets-Live17',
                'ICMarkets-Live18',
                'ICMarkets-Live19',
                'ICMarkets-Live20',
                'ICMarkets-Live22',
                'ICMarkets-Live23',
                'ICMarkets-Live24'
            ],
            server: 'ICMarkets-Live01',
            demoAllServers: false,
            startMode: "open_demo",
            lang: "en",
            colorScheme: "black_on_white"
        } );
    </script>
    <!-- Web Terminal Code End -->

    <div id="footer">
        <span class="copyright">&copy;&nbsp;2019 International Capital Markets Pty. Ltd.</span>
        <span class="secure"> </span>
    </div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

通过JavaScript动态加载内容时, Selenium 库可能更适用。