来自URL的源代码

时间:2017-08-11 13:07:53

标签: python-3.x urllib

我正在尝试从url获取源代码,以在python中构建应用程序。我用了

from urllib.request import urlopen
html = urlopen("http://www.google.com/")
print(html.code)

这会返回HTTP代码(200) 我该怎么做才能获得HTML代码(内容在'查看源代码'页面)?

1 个答案:

答案 0 :(得分:2)

您必须使用read方法来获取源代码。

<table>

    <?php 
    foreach($EMPLOYEES as $employee) {
        $employee = (object)$employee;
    ?>

    <tr>
        <td><?=$employee->id_acd;?></td>
        <td><?=$employee->nombre;?></td>
        <td><?=$employee->apellido;?></td>

    <td>
            <button data-toggle="modal"
            data-target="#myModal"
            data-employee-id="<?=$employee->id_acd;?>">
            </button>
        </td>
    </tr>

    <?php } ?>

</table>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
 <div class="modal-dialog">
 <div class="modal-content">
 <div class="modal-body">
<form name="myModalTitle" id="myModalTitle" method="post" action="<?php
            echo site_url('user_Authentication/user_login_process');?>">
  <div> 
  <label>Nombre:</label>
 <input name="nombre" value="{{nombre}}" disabled>
     </div>
   <div class="form-group">
    <label>Apellido:</label>
    <input type="text" class="form-control" name="apellido"
   value="{{apellido}}" disabled>
  </div>
  <p>
    <button> Enviar </button>
  </p>
 </form>
    <script>
      var employees = <?=
    json_encode(
    $EMPLOYEES
    ); ?>;
     (function($){
     var myModalTitle = $( '#myModalTitle' );
    var myModalTitleText = myModalTitle.html();
   var myModal = $( '#myModal' );
   var btnOpenMyModal = $( '.btn-open-my-modal' );
   btnOpenMyModal.on('click', function() {
   var btn = $( this );
   var currentEmployees = employees[parseInt( btn.data( 'employee-id' ) )];
   myModalTitle.html(
  .replace( '{{nombre}}', currentEmployees.nombre )
     currentEmployees.telefono )
     );
     });
      }(jQuery));
     </script>