Python硒:如何从iframe内容中获取html正文文本

时间:2019-04-08 06:30:31

标签: python selenium selenium-webdriver

我正在研究python硒自动化,我必须从驻留在iframe内容中的HTML页面正文中获取文本内容

我尝试了以下代码来实现python硒,要从HTML页面获取链接为“ https://novationleasing.com.au/?token=17fef55j0L-a6555147-59bc-11e9-bef5-00155da40d82

iframe1 = driver.find_element_by_class_name("cke_wysiwyg_frame ")
driver.switch_to.frame(iframe1)
link = driver.find_element_by_xpath("/html/body/p[2]/text()[2]").text

我想从html中获取/html/body/p[2]/text()[2]。我遇到错误

  

无效的选择器:xpath表达式的结果   “ / html / body / p [2] / text()[2]”是:[对象文本]。应该是   元素。

屏幕截图 Html_page_screen_shot

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>
   Online Application
Email View FirstNameCheck (FirstNameCheck) MiddleName Last_Name - LID 315691 - 
   EVOv30.3.6 (DEVELOPMENT)</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">

  <script type="text/javascript" src="/evo-static/jquery-1.11.3.js"></script><script type="text/javascript">
      var rumMOKey='b7f6f947d34b1aac3a41411c716e902c';
      (function(){
          if(window.performance && window.performance.timing && window.performance.navigation) {
              var site24x7_rum_beacon=document.createElement('script');
              site24x7_rum_beacon.async=true;
              site24x7_rum_beacon.setAttribute('src','//static.site24x7rum.com/beacon/site24x7rum-min.js?appKey='+rumMOKey);
              document.getElementsByTagName('head')[0].appendChild(site24x7_rum_beacon);
          }
      })(window)
  </script>
 

  <script type="text/javascript" src="/evo-static/jquery-ui-1.12.1/jquery-ui.js"></script>
  <link type="text/css" rel="stylesheet" href="/evo-static/jquery-ui-themes-1.12.1/themes/smoothness/jquery-ui.css">

  

  <script type="text/javascript" src="/evo-static/ckeditor/ckeditor.js?v=20190409T082732"></script>
  <script type="text/javascript" src="/evo-static/ckeditor/adapters/jquery.js?v=20190409T082732"></script>
  <script type="text/javascript" src="/evo-static/ckeditorconfig.js?v=20190409T082732"></script>
  <script type="text/javascript" src="/evo-static/app.js?v=20190409T082732"></script>

  <script type="text/javascript" src="/evo-static/autoNumeric-4.2.0.min.js"></script>
  <script type="text/javascript">$(document).ready(function() {
   if ($('.auto-numeric-money').length > 0)
    AutoNumeric.multiple('.auto-numeric-money', AutoNumeric.getPredefinedOptions().dotDecimalCharCommaSeparator);
   if ($('.auto-numeric-integer').length > 0)
    AutoNumeric.multiple('.auto-numeric-integer', { decimalPlaces: 0, digitGroupSeparator: ',' });
   if ($('.auto-numeric-percentage').length > 0)
    AutoNumeric.multiple('.auto-numeric-percentage',
     {decimalPlaces: 2, digitGroupSeparator: ',', maximumValue: "100", minimumValue: "0", suffixText: "%", unformatOnSubmit: true});
   if ($('.auto-numeric-number').length > 0)
    AutoNumeric.multiple('.auto-numeric-number', { decimalPlaces: 0, digitGroupSeparator: '' });
  });
  </script><link type="text/css" href="/evo-static/style.css?v=20190409T082732" rel="stylesheet">
  <link type="image/x-icon" href="/evo-static/favicon.ico?v=20190409T082732" rel="icon">

  <script type="text/javascript">
  evo_idle_check_failed = false;
  function evo_idle_check() {
   if (evo_idle_check_failed) return;
   $.ajax({ type: 'GET',
    url: 'evo_lookup',
    dataType: 'json',
    data: {
     lookup: 'idle',
     value: app_generate_uuid(),
     },
    timeout: 60000, // 1 minute
    success: evo_idle_check_success,
    error: evo_idle_check_error,
   });
  }
  function evo_idle_check_success(data, textStatus, jqXHR) {
   if (evo_idle_check_failed) return;
   if (!data['value']) evo_idle_check_error(jqXHR, textStatus, 'Logged out');
  }
  function evo_idle_check_error(jqXHR, textStatus, errorThrown) {
    evo_idle_check_failed = true;
    alert('Login session timed out');
    window.location.replace('/evo/main');
  }
  $(document).ready(function() {
   evo_idle_check_failed = false;
   window.setInterval(evo_idle_check, 3600000); // 1 hour
  });
  </script>
  </head>

 <body>
  <div id="Main">
   <div id="Nav">
    <ul>
     <li id="Nav_main"><a href="/evo/main">Main</a></li>
     <li id="Nav_consultant"><a href="/evo/consultant">Consultant View</a></li>
     <li id="Nav_customer_search"><a href="/evo/customer_search">Customer Search</a></li>
     <li id="Nav_dealers"><a href="/evo/dealers">Dealers</a></li>
     <li id="Nav_vehicle_tree"><a href="/evo/vehicle_tree">Vehicles</a></li>
     <li id="Nav_admin"><a href="/evo/admin">Admin</a></li>
     <li id="Nav_nlci_manage"><a href="/evo/nlci_manage">nlcI Manage</a></li>
     <li id="Nav_logout"><a href="/evo/logout">Logout</a></li>
     <li id="Nav_user">
       <span title="Logged in user">
        Automation Test &lt;automation.test&gt;
       </span>
      </li>
     <li id="Nav_version">
      <span title="EVOv30.3.6 (DEVELOPMENT)">
       EVOv30.3.6</span>
     </li>
     <li id="Nav_devtest">
       <span title="DEV/TEST version">
        TEST@nlcsvrspk16c-t
        EVOv30.3.6</span>
      </li>
     </ul>
   </div>
  </div>

  <div id="ContentBlock">

   <div class="StatusPanel">
    <div class="StatusMessage">
    TEST system. For new Development and testing relating to that. Please use DEMO system if Production comparisons are needed.</div>
   </div>
   <div id="ErrorPanel"></div>
   <div id="WarningPanel"></div>
   <div id="StatusPanel"></div>
   <script type="text/javascript">
 $(document).ready(function() {
   CKEDITOR.replace('email_body_text', {
     customConfig: '/evo-static/ckeditorconfig.js',
     toolbar: 'NLCShow',
     readOnly: true
   });
 });
</script>

<form method="POST" action="/evo/email_view"><div class="ContentColumn">
 <table>
  <tr>
  <th class="text-right-bold">Client:</th>
  <td><i><b>sg</b>fleet</i> - Police Department (Vic) </td>
  <th class="text-right-bold">Customer:</th>
  <td title="Customer View/Edit"><a href="customer?evo_customer_id=254610"><b>Madam</b> FirstNameCheck (FirstNameCheck) <i>MiddleName</i> <b>Last_Name</b></a></td>
   </td>
  <th class="text-right-bold">Consultant:</th>
  <td title="Consultant View"><a href="consultant?application_user_id=750">Automation Test &lt;automation.test&gt; (Non - Sales)</a></td>
  <th class="text-right-bold">Lead:</th>
  <td>Novated Finance Lease, Vehicle purchase, LID315691 ( <a href="lead?evo_lead_id=315691">View/Edit</a>,
   <a href="doc_lead?evo_lead_id=315691">Print/Email</a> )
  </td>
<th class="text-right-bold">Quote:</th>
  <td>QID657319 MAZDA CX-7 CLASSIC SPORTS (4x4) ER MY10 JTL09J N/A Unleaded ( <a href="quote?evo_quote_id=657319">View/Edit</a>, 
   <a href="doc_lead?evo_lead_id=315691&amp;evo_quote_id=657319">Print/Email</a> )
  </td>
 </tr>
<tr>
  <th class="text-right-bold">Quote Result ID:</th>
  <td nowrap>
   1572597 ( <a href="doc_lead?evo_lead_id=315691&amp;evo_quote_id=657319">Print/Email</a> )
  </td>
  <th class="text-right-bold">Description:</th>
  <td colspan="3">
   MAZDA CX-7 CLASSIC SPORTS (4x4) ER MY10 JTL09J N/A Unleaded<hr style="margin: 1pt 1pt 1pt 1pt;"/>
   <span style="font-size: 0.9em">Novated Finance Lease, Vehicle purchase, Statutory, Employee Contribution Method (ECM), Fortnightly</span>
   <hr style="margin: 1pt 1pt 1pt 1pt;"/>
   <span style="font-size: 0.9em">2 months in arrears 2 deferred + 46 monthly finance payments inc gst $99.79 (ex gst: $90.72) purchase price inc gst $5,800.00</span>
  </td>
  <td colspan="4">
   <table class="inside" style="font-size: 0.9em;" width="100%">
    <tr class="cssbg">
     <th class="text-right-bold">Annual:</th>
     <td class="text-right-bold">Pre Tax</td>
     <td class="number-right">$8,400.51</td>
     <td class="text-right-bold">Post Tax</td>
     <td class="number-right">$1,160.00</td>
     <td class="text-right-bold">After Tax Benefit</td>
     <td class="number-right">$3,867.79</td>
     <td class="text-right-bold">Package Cost</td>
     <td class="number-right">$9,560.51</td>
     <td class="text-right-bold">Hip Pocket Cost</td>
     <td class="number-right">$6,284.51</td>
     </tr>
    <tr class="cssbg">
     <th class="text-right-bold">Fortnightly:</th>
     <td class="text-right-bold">Pre Tax</td>
     <td class="number-right">$323.10</td>
     <td class="text-right-bold">Post Tax</td>
     <td class="number-right">$44.62</td>
     <td class="text-right-bold">After Tax Benefit</td>
     <td class="number-right">$148.76</td>
     <td class="text-right-bold">Package Cost</td>
     <td class="number-right">$367.72</td>
     <td class="text-right-bold">Hip Pocket Cost</td>
     <td class="number-right">$241.71</td>
     </tr>
   </table>
   </td>
 </tr>
</table>
 <input type="hidden" name="email_record_id" value="784152" /><div style="float: left">
  <h3>Online Application Email</h3>
  <table class="plain">
   <tbody>
    <tr>
     <th class="text-right-bold">From:</th>
     <td>Automation Test &lt;lob-test@nlc.com.au&gt;</td>
    </tr>
    <tr>
     <th class="text-right-bold">To:</th>
     <td>firstname.lastname@gmail.com</td>
    </tr>
    <tr>
     <th class="text-right-bold">Subject:</th>
     <td>Online Finance Application for FirstNameCheck (FirstNameCheck) MiddleName Last_Name VSSS 1572597</td>
    </tr>
    <tr>
     <th class="text-right-bold">Sent:</th>
     <td>08-Apr-2019 15:10:43</td>
    </tr>
    <tr>
     <th class="text-right-bold">Message-ID:</th>
     <td><small>&lt;155470024371.56988.15075359144788681573.online_application.784152.750.EVOv30.3.5 (DEVELOPMENT)@nlcsvrspk16b-t.headoffice.novationleasing.com.au&gt;</small></td>
    </tr>
    </tbody>
  </table>

 </div>

 <div style="float: left">

  <h3>Contents (For Display Only - changes will NOT be saved)</h3>
  <textarea rows="80" id="email_body_text" name="email_body_text">&lt;html&gt;
 &lt;body&gt;
 &lt;p&gt;
  Good Afternoon FirstNameCheck,
 &lt;/p&gt;
 &lt;p&gt;
  The link below will direct you to our on-line finance application so we can confirm your eligibility for your Novated Lease.&lt;br/&gt;
  &lt;br/&gt;
  &lt;a href=&quot;https://novationleasing.com.au/?token=17fef55j0L-a6555147-59bc-11e9-bef5-00155da40d82&quot;&gt;https://novationleasing.com.au/?token=17fef55j0L-a6555147-59bc-11e9-bef5-00155da40d82&lt;/a&gt;
 &lt;/p&gt;
 &lt;p&gt;
  So we know that it is you and to protect your privacy, please have your mobile phone handy to complete the 2-step SMS
  verification process before you get underway.&amp;#160;
 &lt;/p&gt;
 &lt;p&gt;
  We generally receive feedback from the financier within 24hrs, so as soon as we do, we will be in touch to advise you
  of the outcome.
 &lt;/p&gt;
 &lt;p&gt;
  If you have any questions at all please do not hesitate to contact me on the details below.
 &lt;/p&gt;
 &lt;p&gt;
  Kind regards,
 &lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;
</textarea></div>
 <br/>
 <div class="ButtonBar">
  <div style="float: left">
   <input target="_blank" type="submit" name="download" value="Download" />
  </div>
  <div style="float: right">
   <input type="submit" name="lead" value="Lead" />
  </div>
 </div>

</div>
<div><input type="hidden" name="__albform__" value="eJx7tNe8cvLUD+0dKu3XA89/nymkpv2sgam2kFEjlD81NzEzJz4pP6UyviS1oqSQyZsBJliUmpxf
lBKfmVLI7M1QqgcASeYbvg==
" /></div>
</form></div>
  <div id="Footer">
   <ul>
    <li>&nbsp;</li>
    <li id="Nav_devtest"><span title="DEV/TEST version">
    TEST@nlcsvrspk16c-t EVOv30.3.6</span></li>
    </ul>
  </div>
 </body>
</html>

0 个答案:

没有答案