2016-02-22 2 views
0

Я хочу преобразовать запрос javascript в тело или текст HTML, но я не знаю, как это сделать. Цель - http://www.americandent.es/ficha-producto.php?id=19373, а последнее число - переменное.Scrape query JavaScript с scrapy

код:

class AmericanSpider(scrapy.Spider): 
    name = 'American2' 
    start_urls = ['http://www.americandent.es/inicio/log-0'] 
    allowed_domains = ['americandent.es'] 
    def parse(self, response): 
     return [FormRequest.from_response(response, 
        formdata={'username': 'name', 'password': 'secret'}, 
        callback=self.after_login)] 


    # continue scraping with authenticated session... 
    def after_login(self, response): 
    # check login succeed before going on 
     if "authentication failed" in response.body: 
      self.logger.error("Login failed") 
      return 
    # We've successfully authenticated, let's have some fun! 
     else: 
      print('LOGG!') 
      for num in range(1,25000): 
       yield Request(url='http://www.americandent.es/ficha-producto.php?id='+str(num), 
        callback=self.parse_tastypage) 


    def parse_tastypage(self, response): 
     cont=0 
     parsed_body = html.fromstring(response.text) 
     item=StackItem() 
     print(parsed_body) 
     for sel in parsed_body.xpath('//*[@id="lightbox-home"]//text()'): 
      #codigo producto = reference 
      item['reference'] = sel.xpath('//*[@id="codigo_producto"]//text()').extract() 
      item['name'] = sel.xpath('//*[@id="nombre_producto"]//text()').extract() 
      #tarifa = price 
      item['price'] = sel.xpath('//*[@id="lb-tarifas"]/div/div[2]/p/strong//text()').extract() 
      item['stock'] = sel.xpath('//*[@id="stock_actual"]//text()').extract() 
      item['imagen'] = sel.xpath('//*[@id="stock"]/img//@src').extract() 
     return item 

EDIT:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <!--Stylesheets--> 

    <!--<link href="http://www.americandent.es/css/main.css" rel="stylesheet" type="text/css" media="screen" charset="utf-8" /> 
    <link href="http://www.americandent.es/css/styles-registro.css" rel="stylesheet" type="text/css" media="screen" charset="utf-8" /> 
    <link href="http://www.americandent.es/css/../js/jquery.fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet" type="text/css" media="screen" charset="utf-8" /> 
    --> 
    <style type="text/css"> 
    .select_cont { 
     background: url("http://www.americandent.es/images/bg_select_2.png") no-repeat scroll left -35px transparent; 
     float: left; 
     height: 29px; 
     margin-bottom: 19px; 
     outline: medium none; 
     padding-left: 4px; 
     position: relative; 
    } 
    .select_cont .eleccion { 
     background: url("http://www.americandent.es/images/bg_select_2.png") no-repeat scroll right top transparent; 
     cursor: default; 
     font-size: 12px; 
     font-weight: bold; 
     height: 100%; 
     line-height: 29px; 
     margin-right: 18px; 
     padding: 0 26px 0 6px; 
     width: 256px; 
    } 
    .panel { 
     display: none; 
     left: 0; 
     position: absolute; 
     top: 31px; 
     z-index: 10; 
    } 
    .panel ul { 
     background-color: #E6E6E6; 
     border-left: 1px solid #D8D5D5; 
     border-right: 1px solid #D8D5D5; 
     font-size: 12px; 
     margin: 0; 
     max-height: 21em; 
     overflow: auto; 
     padding: 0; 
     width: 290px; 
    } 
    .panel li { 
     cursor: default; 
     height: 25px; 
     line-height: 25px; 
     padding: 0 12px; 
    } 
    .select_cont .eleccion { width:315px } 
    .panel ul { width:349px } 
    .panel .sup_panel { 
     height:4px; 
     background:url("http://www.americandent.es/images/sup_inf_panel2.png") no-repeat; 
    } 
    .panel .inf_panel { 
     height:4px; 
     background:url("http://www.americandent.es/images/sup_inf_panel2.png") no-repeat bottom; 
    } 
     .capa_de_grupo { 
      display:none; 
     } 
    </style>  
</head> 
<body>  
    <div id="lightbox-home"> 
    <div id="mensaje"> 
      <h3>El producto ha sido a&ntilde;adido con &eacute;xito a tu carrito.</h3> 
      <p>Podr&aacute;s proceder al pago de los productos a&ntilde;adidos mediante el acceso a 'Carrito' del men&uacute; principal de la web. Te invitamos a seguir navegando por nuestro cat&aacute;logo de productos. Gracias.</p> 
      <img class="cerrar" src="http://www.americandent.es/images/close.png" alt="cerrar" title="cerrar" /> 
    </div> 
    <div id="mensaje_error"> 
      <h3>No se ha a&ntilde;adido el producto a tu carrito.</h3> 
      <p>Parece que ha habido un error al intentar a&ntilde;adir el producto a tu carrito. Por favor, int&eacute;ntalo de nuevo pasados unos minutos.</p> 
      <img class="cerrar" src="http://www.americandent.es/images/close.png" alt="cerrar" title="cerrar" /> 
    </div> 
    <div id="mensaje_unidades_error"> 
      <h3>Ya has añadido las unidades a tu carrito.</h3> 
      <p>Por favor, espera unos segundos para poder añadir más unidades.</p> 
      <img class="cerrar" src="http://www.americandent.es/images/close.png" alt="cerrar" title="cerrar" /> 
    </div> 
    <div id="mensaje_stock_error"> 
      <h3>No hay stock disponible.</h3> 
      <p>No hay más unidades disponibles de este producto para añadir a tu carrito.</p> 
      <img class="cerrar" src="http://www.americandent.es/images/close.png" alt="cerrar" title="cerrar" /> 
    </div>  
    <input type="hidden" id="id_producto" value="19373" /> 
    <input type="hidden" id="uds_en_carrito" value="0" /> 
    <div id="inline"> 
      <div id="stock"> 
       <img src="http://www.americandent.es/imagenes/productos/19373/th3_3+1reposicionesprimeandbond.jpg" alt="00 Prime & Bond Nt Promo Pack Doble (4x4,5ml.+ 2x2,5ml)" alt="" /> 
            <div id="lb-comprar" > 
         <p>COMPRAR </p> 
      <div id="lb-unidades"> 
          <form id="lb-formulario" action="" method="post"> 
          <div class="clearUnidades"> 
          <img src="http://www.americandent.es/images/bg_login-L.png" alt="" /> 
       <input class="inputNormal-lb" type="text" id="inputUnidades" value="1"> 
          <img src="http://www.americandent.es/images/bg_login-R.png" alt="" /> 
          </div> 
          <h3>unidades</h3> 
         <img src="http://www.americandent.es/images/ln_lightbox.png" alt="" /> 
          <div class="clearAnadir"> 
           <a class="buttonAnadir icoAn " href="#"> 
           <span>A&ntilde;adir al carrito</span></a> 
          </div> 
          <div id="anadir_loading"><img src="http://www.americandent.es/images/ajax-loader.gif" /></div> 
          </form> 
      </div> <!--lb-unidades--> 
        </div> 
           <div id="ofVinculada"> 
             </div> 
      </div> 

      <div id="detalle"> 
       <div id="lb-descripcion"> 
           <h1 id="nombre_producto">00 Prime & Bond Nt Promo Pack Doble (4x4,5ml.+ 2x2,5ml)</h1> 
       <p>OBTURACION > ADHESIVOS</p> 
       <p>Fabricante: DENTSPLY</p> 
       <h4>C&oacute;digo: <span id="codigo_producto">02CA60667238</span></h4> 

                   <p><strong>Stock:</strong> <span id="stock_actual">16</span> u</p> 
           <p><strong>Stock pr&oacute;ximo:</strong> <span id="stock_prevision">0</span>u <span id='fecha_stock'></span></p> 
               <p style="max-height:130px;overflow:auto"><br /> 
       </p> 
      </div> 

       <div id="lb-tarifas"> 
        <p><strong>TARIFAS </strong></p>     
              <div class="tarifas"> 
                   <div class="lb-linea"></div> 
            <div class="lb-tarifaseuros"><p><strong>231,01&euro; </strong></p></div> 
            <p>Su tarifa</p> 
                  </div> 
       </div> 

      </div> <!--detalle--> 
    </div>   
    </div> 
<script type="text/javascript"> 
$(".select_cont").desplegable(); 
</script> 
</body> 

Теперь я хочу, чтобы подвести итоги, название, ссылку, описание и т.д., но проблема в том, что взять URL, PHP не принимает любой контент, потому что я думаю, что он делает запрос

+0

Можете ли вы предоставить образец HTML или Javascript код, который нужно извлечь данные из? предоставленные вами URL-адреса не отображаются для меня. –

+0

Вы можете увидеть пример. – Jatet

+0

Извините, но я не вижу никакого тега '