2016-11-03 5 views
0

ウェブサイトから値をフェッチない、私を助けてください:Scrapy私は予想通り、それは動作しませんが、何とかこの特定の1つの私のロジックでは、作業の前にscrapyコードを書かれている

マイitems.py:

import scrapy 

class KohlItem(scrapy.Item): 
    images=scrapy.Field() 
    links=scrapy.Field() 
    name=scrapy.Field() 
    title=scrapy.Field() 

マイfirst.py:

import scrapy 
from scrapy.spiders import CrawlSpider,Rule 
from scrapy.linkextractors import LinkExtractor 

from scrapy.loader import ItemLoader 
from kohl.items import KohlItem 


class FirstSpider(scrapy.Spider): 
    name = "first" 
    allowed_domains = ["kohls.com"] 
    start_urls = [  
     "http://www.kohls.com/catalog/mens-t-shirts-tops-tees-tops-clothing.jsp?CN=Gender:Mens+Silhouette:T-Shirts+Product:Tops%20%26%20Tees+Category:Tops+Department:Clothing&cc=mens-TN3.0-S-tshirts", 
     "http://www.kohls.com/catalog/mens-t-shirts-tops-tees-tops-clothing.jsp?CN=Gender:Mens+Silhouette:T-Shirts+Product:Tops%20%26%20Tees+Category:Tops+Department:Clothing&cc=mens-TN3.0-S-tshirts&PPP=60&WS=240"] 


    def parse(self, response): 
     #print response.url 

     kk=ItemLoader(item=KohlItem(),response=response) 
     kk.add_xpath('title','//title/text()') 
     kk.add_value('links',response.url) 
     kk.add_xpath('images','//*[@class="pmp-hero-img"]/@src') 
     print 'images ******************' 
     kk.add_xpath('name','//*[@class="prod_nameBlock"]/p/text()') 
     print '******************' 
     return kk.load_item() 

期待通りの出力は私のタイトルを与えているが、残りの値が来ていません。

上記のxpathsはブラウザコンソールでうまく動作しており、期待どおりの出力が得られます。

答えて

0

最初に確認するのは、ページがjavascriptを使用してレンダリングされているかどうかです。そうであれば、webdriverが役立ちます。

関連する問題