2016-08-01 10 views
0

リンクのクロール画像を希望します:「http://vnexpress.net/photo/cuoc-song-do-day/nguoi-trung-quoc-ra-be-boi-danh-mat-chuoc-tranh-nong-3445592.html」しかし、コードは(自分のコンピュータで)画像をクロールし、(友人のコンピュータで)すべての画像をクロールします。 pleseはあなたが[0]のインデックスを指定することにより、1つのリンクのみを取る傷病専用クロール1枚

import scrapy 

from scrapy.contrib.spiders import Rule, CrawlSpider 
from scrapy.contrib.linkextractors import LinkExtractor 
from imgur.items import ImgurItem 

class ImgurSpider(CrawlSpider): 
name = 'imgur' 
allowed_domains = ['vnexpress.net'] 
start_urls = ['http://vnexpress.net/photo/cuoc-song-do-day/nguoi-trung-quoc-ra-be-boi-danh-mat-chuoc-tranh-nong-3445592.html'] 
# rules = [Rule(LinkExtractor(allow=['/*']), 'parse123')] 

def parse(self, response): 
    image = ImgurItem() 
    # image['title'] = response.xpath(\ 
    # "//img[data-notes-url=""]").extract() 
    rel = response.xpath("//div[@id='article_content']//img/@src").extract() 
    image['image_urls'] = [rel[0]] 
    return image 

答えて

0
rel = response.xpath("//div[@id='article_content']//img/@src").extract() 
image['image_urls'] = [rel[0]] 

私を助けてください。 ます。また、解析機能、および画像をダウンロードするためのコールバックをURLにあなたのコードを分割することができ

image['image_urls'] = rel 

試してみてください。

+0

ああ、はい、ありがとうございます –

+0

素晴らしい!それがうまくいけば答えを受け入れることができますか? – Huxwell

関連する問題