亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

scrapy學(xué)習(xí)之路2(圖片下載與下載的路徑獲取)

WelliJhon / 871人閱讀

摘要:圖片下載和拿到下載后的路徑小封面圖的爬取,后面通過(guò)傳到中詳情頁(yè)的爬取詳情頁(yè)的完整地址下一頁(yè)的爬取與請(qǐng)求不明打開(kāi)功能注意如要進(jìn)一步定制功能補(bǔ)充新建

圖片下載和拿到下載后的路徑 1

items.py

import scrapy

class InfoItem(scrapy.Item):
    url = scrapy.Field()
    url_object_id = scrapy.Field()
    small_image = scrapy.Field()
    small_image_path = scrapy.Field()
    big_image = scrapy.Field()
    big_image_path = scrapy.Field()
    code = scrapy.Field()
    date = scrapy.Field()
    lengths = scrapy.Field()
    author = scrapy.Field()
    cate = scrapy.Field()
    av_artor = scrapy.Field()

spider/jxxx.py

# -*- coding: utf-8 -*-
import scrapy
from urllib import parse
from scrapy.http import Request
from JaSpider.items import InfoItem
from JaSpider.utils.common import get_md5


class JxxxSpider(scrapy.Spider):
    name = "jxxx"
    allowed_domains = ["www.jxxx.com"]
    start_urls = ["http://www.jxxx.com/cn/vl_update.php"]

    def parse(self, response):
        for i in response.css(".video"):
            small_image = i.css("img::attr(src)").extract_first() # 小封面圖的爬取,后面通過(guò)meta傳到parse_info中
            link = i.css("a::attr(href)").extract_first() # 詳情頁(yè)的url爬取
            real_url = parse.urljoin(response.url, link) # 詳情頁(yè)的完整地址
            yield Request(url=real_url, meta={"small_image": small_image}, callback=self.parse_info)
        # 下一頁(yè)的爬取與請(qǐng)求    
        next_url = response.css(".page_selector .page.next::attr(href)").extract_first()
        perfect_next_url = parse.urljoin(response.url, next_url)
        if next_url:
            yield Request(url=perfect_next_url, callback=self.parse)

    def parse_info(self, response):
        small_image = "http:"+response.meta["small_image"]
        big_image = "http:"+response.xpath("http://div[@id="video_jacket"]/img/@src").extract_first()
        code = response.css("#video_id .text::text").extract_first()
        date = response.css("#video_date .text::text").extract_first()
        lengths = response.css("#video_length .text::text").extract_first()
        author = response.css("#video_director .director a::text").extract_first() if response.css("#video_director .director a::text").extract_first() else "不明"
        cate = ",".join([i.css("a::text").extract_first() for i in response.css("#video_genres .genre") if i.css("a::text").extract_first()])
        av_artor = ",".join([i.css("a::text").extract_first() for i in response.css(".star") if i.css("a::text").extract_first()])
        # print("http:"+small_image)
        info_item = InfoItem()
        info_item["url"] = response.url
        info_item["url_object_id"] = get_md5(response.url)
        info_item["small_image"] = small_image
        info_item["big_image"] = [big_image]
        info_item["code"] = code
        info_item["date"] = date
        info_item["lengths"] = lengths
        info_item["author"] = author
        info_item["cate"] = cate
        info_item["av_artor"] = av_artor
        yield info_item
2

打開(kāi)pipeline功能 settings.py


注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:
spider/jxxx.py

3

如要進(jìn)一步定制功能
settings.py

pipeline.py

4

補(bǔ)充
新建utils/common.py

import hashlib


def get_md5(url):
    if isinstance(url, str):
        url = url.encode("utf-8")
    m = hashlib.md5()
    m.update(url)
    return m.hexdigest()


if __name__ == "__main__":
    a = get_md5("http://www.haddu.com")
    print(a)

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/41201.html

相關(guān)文章

  • scrapy 學(xué)習(xí)之路那些坑

    摘要:前言本文記錄自己在學(xué)習(xí)當(dāng)中遇到的各種大小問(wèn)題,持續(xù)更新。錯(cuò)誤分析本身是一個(gè)網(wǎng)絡(luò)引擎框架,的運(yùn)行依賴于。在打開(kāi)新建的項(xiàng)目后,報(bào)錯(cuò)顯示。錯(cuò)誤分析的默認(rèn)依賴項(xiàng)當(dāng)中沒(méi)有,或者說(shuō)默認(rèn)查找的路徑中找不到。 前言 本文記錄自己在學(xué)習(xí)scrapy當(dāng)中遇到的各種大小問(wèn)題,持續(xù)更新。 環(huán)境簡(jiǎn)介: 語(yǔ)言版本 爬蟲(chóng)框架 IDE 系統(tǒng) python3.5 scrapy1.4.0 pycharm win1...

    xiaodao 評(píng)論0 收藏0
  • scrapy學(xué)習(xí)之路1(簡(jiǎn)單例子)

    摘要:的安裝環(huán)境是后面創(chuàng)建用來(lái)運(yùn)行的名網(wǎng)站域名在創(chuàng)建可以通過(guò)此文件運(yùn)行本文件名父文件名路徑和父文件名設(shè)置環(huán)境,必須以上運(yùn)行可能在下會(huì)報(bào)錯(cuò)準(zhǔn)備工作完在下獲取列表頁(yè)每一個(gè)的把獲取到的交給 scrapy的安裝 環(huán)境:python3.6 1 pip install -i https://pypi.douban.com/simple/ scrapy 2 scrapy startpr...

    guqiu 評(píng)論0 收藏0
  • 20、 Python快速開(kāi)發(fā)分布式搜索引擎Scrapy精講—編寫(xiě)spiders爬蟲(chóng)文件循環(huán)抓取內(nèi)容

    摘要:百度云搜索,搜各種資料搜網(wǎng)盤(pán),搜各種資料編寫(xiě)爬蟲(chóng)文件循環(huán)抓取內(nèi)容方法,將指定的地址添加到下載器下載頁(yè)面,兩個(gè)必須參數(shù),參數(shù)頁(yè)面處理函數(shù)使用時(shí)需要方法,是庫(kù)下的方法,是自動(dòng)拼接,如果第二個(gè)參數(shù)的地址是相對(duì)路徑會(huì)自動(dòng)與第一個(gè)參數(shù)拼接導(dǎo) 【百度云搜索,搜各種資料:http://bdy.lqkweb.com】 【搜網(wǎng)盤(pán),搜各種資料:http://www.swpan.cn】 編寫(xiě)spiders爬...

    CntChen 評(píng)論0 收藏0
  • windows下安裝python+scrapy

    摘要:好啦一切準(zhǔn)備工作就緒,現(xiàn)在開(kāi)始安裝庫(kù)安裝成功后,安裝就簡(jiǎn)單了,在命令提示符窗口直接輸入命令回車(chē)現(xiàn)在一切都搞定了,可以新建一個(gè)測(cè)試,敲一個(gè)基于框架的爬蟲(chóng)程序咯。 最近忽然有了想要學(xué)習(xí)python爬蟲(chóng)的想法,但是首先需要安裝工具。python安裝倒是很輕松,只要傻瓜式一鍵安裝即可,但是在Windows下安裝scrapy倒不是件容易的事情。言歸正傳,說(shuō)下我從昨天下午到今天上午安裝的步驟: 1...

    dantezhao 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<