scrapy爬蟲框架介紹

来源:https://www.cnblogs.com/wxp5257/archive/2018/01/24/8343093.html
-Advertisement-
Play Games

一 介紹 Scrapy一個開源和協作的框架,其最初是為了頁面抓取 (更確切來說, 網路抓取 )所設計的,使用它可以以快速、簡單、可擴展的方式從網站中提取所需的數據。但目前Scrapy的用途十分廣泛,可用於如數據挖掘、監測和自動化測試等領域,也可以應用在獲取API所返回的數據(例如 Amazon As ...


一 介紹

    Scrapy一個開源和協作的框架,其最初是為了頁面抓取 (更確切來說, 網路抓取 )所設計的,使用它可以以快速、簡單、可擴展的方式從網站中提取所需的數據。但目前Scrapy的用途十分廣泛,可用於如數據挖掘、監測和自動化測試等領域,也可以應用在獲取API所返回的數據(例如 Amazon Associates Web Services ) 或者通用的網路爬蟲。

    Scrapy 是基於twisted框架開發而來,twisted是一個流行的事件驅動的python網路框架。因此Scrapy使用了一種非阻塞(又名非同步)的代碼來實現併發。整體架構大致如下

The data flow in Scrapy is controlled by the execution engine, and goes like this:

  1. The Engine gets the initial Requests to crawl from the Spider.
  2. The Engine schedules the Requests in the Scheduler and asks for the next Requests to crawl.
  3. The Scheduler returns the next Requests to the Engine.
  4. The Engine sends the Requests to the Downloader, passing through the Downloader Middlewares (see process_request()).
  5. Once the page finishes downloading the Downloader generates a Response (with that page) and sends it to the Engine, passing through the Downloader Middlewares (see process_response()).
  6. The Engine receives the Response from the Downloader and sends it to the Spider for processing, passing through the Spider Middleware (see process_spider_input()).
  7. The Spider processes the Response and returns scraped items and new Requests (to follow) to the Engine, passing through the Spider Middleware (see process_spider_output()).
  8. The Engine sends processed items to Item Pipelines, then send processed Requests to the Scheduler and asks for possible next Requests to crawl.
  9. The process repeats (from step 1) until there are no more requests from the Scheduler.

 

Components:

  1. 引擎(EGINE)

    引擎負責控制系統所有組件之間的數據流,併在某些動作發生時觸發事件。有關詳細信息,請參見上面的數據流部分。

  2. 調度器(SCHEDULER)
    用來接受引擎發過來的請求, 壓入隊列中, 併在引擎再次請求的時候返回. 可以想像成一個URL的優先順序隊列, 由它來決定下一個要抓取的網址是什麼, 同時去除重覆的網址
  3. 下載器(DOWLOADER)
    用於下載網頁內容, 並將網頁內容返回給EGINE,下載器是建立在twisted這個高效的非同步模型上的
  4. 爬蟲(SPIDERS)
    SPIDERS是開發人員自定義的類,用來解析responses,並且提取items,或者發送新的請求
  5. 項目管道(ITEM PIPLINES)
    在items被提取後負責處理它們,主要包括清理、驗證、持久化(比如存到資料庫)等操作
  6. 下載器中間件(Downloader Middlewares)
    位於Scrapy引擎和下載器之間,主要用來處理從EGINE傳到DOWLOADER的請求request,已經從DOWNLOADER傳到EGINE的響應response,你可用該中間件做以下幾件事
    1. process a request just before it is sent to the Downloader (i.e. right before Scrapy sends the request to the website);
    2. change received response before passing it to a spider;
    3. send a new Request instead of passing received response to a spider;
    4. pass response to a spider without fetching a web page;
    5. silently drop some requests.
  7. 爬蟲中間件(Spider Middlewares)
    位於EGINE和SPIDERS之間,主要工作是處理SPIDERS的輸入(即responses)和輸出(即requests)

官網鏈接:https://docs.scrapy.org/en/latest/topics/architecture.html

二 安裝

#Windows平臺
    1、pip3 install wheel #安裝後,便支持通過wheel文件安裝軟體,wheel文件官網:https://www.lfd.uci.edu/~gohlke/pythonlibs
    3、pip3 install lxml
    4、pip3 install pyopenssl
    5、下載並安裝pywin32:https://sourceforge.net/projects/pywin32/files/pywin32/
    6、下載twisted的wheel文件:http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted
    7、執行pip3 install 下載目錄\Twisted-17.9.0-cp36-cp36m-win_amd64.whl
    8、pip3 install scrapy
  
#Linux平臺
    1、pip3 install scrapy

三 命令行工具

#1 查看幫助
    scrapy -h
    scrapy <command> -h

#2 有兩種命令:其中Project-only必須切到項目文件夾下才能執行,而Global的命令則不需要
    Global commands:
        startproject #創建項目
        genspider    #創建爬蟲程式
        settings     #如果是在項目目錄下,則得到的是該項目的配置
        runspider    #運行一個獨立的python文件,不必創建項目
        shell        #scrapy shell url地址  在互動式調試,如選擇器規則正確與否
        fetch        #獨立於程單純地爬取一個頁面,可以拿到請求頭
        view         #下載完畢後直接彈出瀏覽器,以此可以分辨出哪些數據是ajax請求
        version      #scrapy version 查看scrapy的版本,scrapy version -v查看scrapy依賴庫的版本
    Project-only commands:
        crawl        #運行爬蟲,必須創建項目才行,確保配置文件中ROBOTSTXT_OBEY = False
        check        #檢測項目中有無語法錯誤
        list         #列出項目中所包含的爬蟲名
        edit         #編輯器,一般不用
        parse        #scrapy parse url地址 --callback 回調函數  #以此可以驗證我們的回調函數是否正確
        bench        #scrapy bentch壓力測試

#3 官網鏈接
    https://docs.scrapy.org/en/latest/topics/commands.html
#1、執行全局命令:請確保不在某個項目的目錄下,排除受該項目配置的影響
scrapy startproject MyProject

cd MyProject
scrapy genspider baidu www.baidu.com

scrapy settings --get XXX #如果切換到項目目錄下,看到的則是該項目的配置

scrapy runspider baidu.py

scrapy shell https://www.baidu.com
    response
    response.status
    response.body
    view(response)
    
scrapy view https://www.taobao.com #如果頁面顯示內容不全,不全的內容則是ajax請求實現的,以此快速定位問題

scrapy fetch --nolog --headers https://www.taobao.com

scrapy version #scrapy的版本

scrapy version -v #依賴庫的版本


#2、執行項目命令:切到項目目錄下
scrapy crawl baidu
scrapy check
scrapy list
scrapy parse http://quotes.toscrape.com/ --callback parse
scrapy bench
    
示範用法

四 項目結構以及爬蟲應用簡介 

project_name/
   scrapy.cfg
   project_name/
       __init__.py
       items.py
       pipelines.py
       settings.py
       spiders/
           __init__.py
           爬蟲1.py
           爬蟲2.py
           爬蟲3.py

文件說明:

  • scrapy.cfg  項目的主配置信息,用來部署scrapy時使用,爬蟲相關的配置信息在settings.py文件中。
  • items.py    設置數據存儲模板,用於結構化數據,如:Django的Model
  • pipelines    數據處理行為,如:一般結構化的數據持久化
  • settings.py 配置文件,如:遞歸的層數、併發數,延遲下載等。強調:配置文件的選項必須大寫否則視為無效,正確寫法USER_AGENT='xxxx'
  • spiders      爬蟲目錄,如:創建文件,編寫爬蟲規則

註意:一般創建爬蟲文件時,以網站功能變數名稱命名

#在項目目錄下新建:entrypoint.py
from scrapy.cmdline import execute
execute(['scrapy', 'crawl', 'xiaohua'])
預設只能在cmd中執行爬蟲,如果想在pycharm中執行需要做
import sys,os
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
關於windows編碼

五 Spiders

1、介紹

#1、Spiders是由一系列類(定義了一個網址或一組網址將被爬取)組成,具體包括如何執行爬取任務並且如何從頁面中提取結構化的數據。

#2、換句話說,Spiders是你為了一個特定的網址或一組網址自定義爬取和解析頁面行為的地方

2、Spiders會迴圈做如下事情

#1、生成初始的Requests來爬取第一個URLS,並且標識一個回調函數
第一個請求定義在start_requests()方法內預設從start_urls列表中獲得url地址來生成Request請求,預設的回調函數是parse方法。回調函數在下載完成返回response時自動觸發

#2、在回調函數中,解析response並且返回值
返回值可以4種:
        包含解析數據的字典
        Item對象
        新的Request對象(新的Requests也需要指定一個回調函數)
        或者是可迭代對象(包含Items或Request)

#3、在回調函數中解析頁面內容
通常使用Scrapy自帶的Selectors,但很明顯你也可以使用Beutifulsoup,lxml或其他你愛用啥用啥。

#4、最後,針對返回的Items對象將會被持久化到資料庫
通過Item Pipeline組件存到資料庫:https://docs.scrapy.org/en/latest/topics/item-pipeline.html#topics-item-pipeline)
或者導出到不同的文件(通過Feed exports:https://docs.scrapy.org/en/latest/topics/feed-exports.html#topics-feed-exports)

3、Spiders總共提供了五種類:

#1、scrapy.spiders.Spider #scrapy.Spider等同於scrapy.spiders.Spider
#2、scrapy.spiders.CrawlSpider
#3、scrapy.spiders.XMLFeedSpider
#4、scrapy.spiders.CSVFeedSpider
#5、scrapy.spiders.SitemapSpider

4、導入使用

# -*- coding: utf-8 -*-
import scrapy
from scrapy.spiders import Spider,CrawlSpider,XMLFeedSpider,CSVFeedSpider,SitemapSpider

class AmazonSpider(scrapy.Spider): #自定義類,繼承Spiders提供的基類
    name = 'amazon'
    allowed_domains = ['www.amazon.cn']
    start_urls = ['http://www.amazon.cn/']
    
    def parse(self, response):
        pass

5、class scrapy.spiders.Spider

這是最簡單的spider類,任何其他的spider類都需要繼承它(包含你自己定義的)。

該類不提供任何特殊的功能,它僅提供了一個預設的start_requests方法預設從start_urls中讀取url地址發送requests請求,並且預設parse作為回調函數

class AmazonSpider(scrapy.Spider):
    name = 'amazon' 
    
    allowed_domains = ['www.amazon.cn'] 
    
    start_urls = ['http://www.amazon.cn/']
    
    custom_settings = {
        'BOT_NAME' : 'Egon_Spider_Amazon',
        'REQUEST_HEADERS' : {
          'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
          'Accept-Language': 'en',
        }
    }
    
    def parse(self, response):
        pass
#1、name = 'amazon' 
定義爬蟲名,scrapy會根據該值定位爬蟲程式
所以它必須要有且必須唯一(In Python 2 this must be ASCII only.)

#2、allowed_domains = ['www.amazon.cn'] 
定義允許爬取的功能變數名稱,如果OffsiteMiddleware啟動(預設就啟動),
那麼不屬於該列表的功能變數名稱及其子功能變數名稱都不允許爬取
如果爬取的網址為:https://www.example.com/1.html,那就添加'example.com'到列表.

#3、start_urls = ['http://www.amazon.cn/']
如果沒有指定url,就從該列表中讀取url來生成第一個請求

#4、custom_settings
值為一個字典,定義一些配置信息,在運行爬蟲程式時,這些配置會覆蓋項目級別的配置
所以custom_settings必須被定義成一個類屬性,由於settings會在類實例化前被載入

#5、settings
通過self.settings['配置項的名字']可以訪問settings.py中的配置,如果自己定義了custom_settings還是以自己的為準

#6、logger
日誌名預設為spider的名字
self.logger.debug('=============>%s' %self.settings['BOT_NAME'])

#5、crawler:瞭解
該屬性必須被定義到類方法from_crawler中

#6、from_crawler(crawler, *args, **kwargs):瞭解
You probably won’t need to override this directly  because the default implementation acts as a proxy to the __init__() method, calling it with the given arguments args and named arguments kwargs.

#7、start_requests()
該方法用來發起第一個Requests請求,且必須返回一個可迭代的對象。它在爬蟲程式打開時就被Scrapy調用,Scrapy只調用它一次。
預設從start_urls里取出每個url來生成Request(url, dont_filter=True)

#針對參數dont_filter,請看自定義去重規則

如果你想要改變起始爬取的Requests,你就需要覆蓋這個方法,例如你想要起始發送一個POST請求,如下
class MySpider(scrapy.Spider):
    name = 'myspider'

    def start_requests(self):
        return [scrapy.FormRequest("http://www.example.com/login",
                                   formdata={'user': 'john', 'pass': 'secret'},
                                   callback=self.logged_in)]

    def logged_in(self, response):
        # here you would extract links to follow and return Requests for
        # each of them, with another callback
        pass
        
#8、parse(response)
這是預設的回調函數,所有的回調函數必須返回an iterable of Request and/or dicts or Item objects.

#9、log(message[, level, component]):瞭解
Wrapper that sends a log message through the Spider’s logger, kept for backwards compatibility. For more information see Logging from Spiders.

#10、closed(reason)
爬蟲程式結束時自動觸發
定製scrapy.spider屬性與方法詳解
去重規則應該多個爬蟲共用的,但凡一個爬蟲爬取了,其他都不要爬了,實現方式如下

#方法一:
1、新增類屬性
visited=set() #類屬性

2、回調函數parse方法內:
def parse(self, response):
    if response.url in self.visited:
        return None
    .......

    self.visited.add(response.url) 

#方法一改進:針對url可能過長,所以我們存放url的hash值
def parse(self, response):
        url=md5(response.request.url)
    if url in self.visited:
        return None
    .......

    self.visited.add(url) 

#方法二:Scrapy自帶去重功能
配置文件:
DUPEFILTER_CLASS = 'scrapy.dupefilter.RFPDupeFilter' #預設的去重規則幫我們去重,去重規則在記憶體中
DUPEFILTER_DEBUG = False
JOBDIR = "保存範文記錄的日誌路徑,如:/root/"  # 最終路徑為 /root/requests.seen,去重規則放文件中

scrapy自帶去重規則預設為RFPDupeFilter,只需要我們指定
Request(...,dont_filter=False) ,如果dont_filter=True則告訴Scrapy這個URL不參與去重。

#方法三:
我們也可以仿照RFPDupeFilter自定義去重規則,

from scrapy.dupefilter import RFPDupeFilter,看源碼,仿照BaseDupeFilter

#步驟一:在項目目錄下自定義去重文件dup.py
class UrlFilter(object):
    def __init__(self):
        self.visited = set() #或者放到資料庫

    @classmethod
    def from_settings(cls, settings):
        return cls()

    def request_seen(self, request):
        if request.url in self.visited:
            return True
        self.visited.add(request.url)

    def open(self):  # can return deferred
        pass

    def close(self, reason):  # can return a deferred
        pass

    def log(self, request, spider):  # log that a request has been filtered
        pass

#步驟二:配置文件settings.py:
DUPEFILTER_CLASS = '項目名.dup.UrlFilter'


# 源碼分析:
from scrapy.core.scheduler import Scheduler
見Scheduler下的enqueue_request方法:self.df.request_seen(request)
去重規則:去除重覆的url
#例一:
import scrapy

class MySpider(scrapy.Spider):
    name = 'example.com'
    allowed_domains = ['example.com']
    start_urls = [
        'http://www.example.com/1.html',
        'http://www.example.com/2.html',
        'http://www.example.com/3.html',
    ]

    def parse(self, response):
        self.logger.info('A response from %s just arrived!', response.url)
        
    
#例二:一個回調函數返回多個Requests和Items
import scrapy

class MySpider(scrapy.Spider):
    name = 'example.com'
    allowed_domains = ['example.com']
    start_urls = [
        'http://www.example.com/1.html',
        'http://www.example.com/2.html',
        'http://www.example.com/3.html',
    ]

    def parse(self, response):
        for h3 in response.xpath('//h3').extract():
            yield {"title": h3}

        for url in response.xpath('//a/@href').extract():
            yield scrapy.Request(url, callback=self.parse)
            
            
#例三:在start_requests()內直接指定起始爬取的urls,start_urls就沒有用了,

import scrapy
from myproject.items import MyItem

class MySpider(scrapy.Spider):
    name = 'example.com'
    allowed_domains = ['example.com']

    def start_requests(self):
        yield scrapy.Request('http://www.example.com/1.html', self.parse)
        yield scrapy.Request('http://www.example.com/2.html', self.parse)
        yield scrapy.Request('http://www.example.com/3.html', self.parse)

    def parse(self, response):
        for h3 in response.xpath('//h3').extract():
            yield MyItem(title=h3)

        for url in response.xpath('//a/@href').extract():
            yield scrapy.Request(url, callback=self.parse)
例子
我們可能需要在命令行為爬蟲程式傳遞參數,比如傳遞初始的url,像這樣
#命令行執行
scrapy crawl myspider -a category=electronics

#在__init__方法中可以接收外部傳進來的參數
import scrapy

class MySpider(scrapy.Spider):
    name = 'myspider'

    def __init__(self, category=None, *args, **kwargs):
        super(MySpider, self).__init__(*args, **kwargs)
        self.start_urls = ['http://www.example.com/categories/%s' % category]
        #...

        
#註意接收的參數全都是字元串,如果想要結構化的數據,你需要用類似json.loads的方法
參數傳遞

6、其他通用Spiders:https://docs.scrapy.org/en/latest/topics/spiders.html#generic-spiders

六 Selectors

#1 //與/
#2 text
#3、extract與extract_first:從selector對象中解出內容
#4、屬性:xpath的屬性加首碼@
#4、嵌套查找
#5、設置預設值
#4、按照屬性查找
#5、按照屬性模糊查找
#6、正則表達式
#7、xpath相對路徑
#8、帶變數的xpath
response.selector.css()
response.selector.xpath()
可簡寫為
response.css()
response.xpath()

#1 //與/
response.xpath('//body/a/')#
response.css('div a::text')

>>> response.xpath('//body/a') #開頭的//代表從整篇文檔中尋找,body之後的/代表body的兒子
[]
>>> response.xpath('//body//a') #開頭的//代表從整篇文檔中尋找,body之後的//代表body的子子孫孫
[<Selector xpath='//body//a' data='<a href="image1.html">Name: My image 1 <'>, <Selector xpath='//body//a' data='<a href="image2.html">Name: My image 2 <'>, <Selector xpath='//body//a' data='<a href="
image3.html">Name: My image 3 <'>, <Selector xpath='//body//a' data='<a href="image4.html">Name: My image 4 <'>, <Selector xpath='//body//a' data='<a href="image5.html">Name: My image 5 <'>]

#2 text
>>> response.xpath('//body//a/text()')
>>> response.css('body a::text')

#3、extract與extract_first:從selector對象中解出內容
>>> response.xpath('//div/a/text()').extract()
['Name: My image 1 ', 'Name: My image 2 ', 'Name: My image 3 ', 'Name: My image 4 ', 'Name: My image 5 ']
>>> response.css('div a::text').extract()
['Name: My image 1 ', 'Name: My image 2 ', 'Name: My image 3 ', 'Name: My image 4 ', 'Name: My image 5 ']

>>> response.xpath('//div/a/text()').extract_first()
'Name: My image 1 '
>>> response.css('div a::text').extract_first()
'Name: My image 1 '

#4、屬性:xpath的屬性加首碼@
>>> response.xpath('//div/a/@href').extract_first()
'image1.html'
>>> response.css('div a::attr(href)').extract_first()
'image1.html'

#4、嵌套查找
>>> response.xpath('//div').css('a').xpath('@href').extract_first()
'image1.html'

#5、設置預設值
>>> response.xpath('//div[@id="xxx"]').extract_first(default="not found")
'not found'

#4、按照屬性查找
response.xpath('//div[@id="images"]/a[@href="image3.html"]/text()').extract()
response.css('#images a[@href="image3.html"]/text()').extract()

#5、按照屬性模糊查找
response.xpath('//a[contains(@href,"image")]/@href').extract()
response.css('a[href*="image"]::attr(href)').extract()

response.xpath('//a[contains(@href,"image")]/img/@src').extract()
response.css('a[href*="imag"] img::attr(src)').extract()

response.xpath('//*[@href="image1.html"]')
response.css('*[href="image1.html"]')

#6、正則表達式
response.xpath('//a/text()').re(r'Name: (.*)')
response.xpath('//a/text()').re_first(r'Name: (.*)')

#7、xpath相對路徑
>>> res=response.xpath('//a[contains(@href,"3")]')[0]
>>> res.xpath('img')
[<Selector xpath='img' data='<img src="image3_thumb.jpg">'>]
>>> res.xpath('./img')
[<Selector xpath='./img' data='<img src="image3_thumb.jpg">'>]
>>> res.xpath('.//img')
[<Selector xpath='.//img' data='<img src="image3_thumb.jpg">'>]
>>> res.xpath('//img') #這就是從頭開始掃描
[<Selector xpath='//img' data='<img src="image1_thumb.jpg">'>, <Selector xpath='//img' data='<img src="image2_thumb.jpg">'>, <Selector xpath='//img' data='<img src="image3_thumb.jpg">'>, <Selector xpa
th='//img' data='<img src="image4_thumb.jpg">'>, <Selector xpath='//img' data='<img src="image5_thumb.jpg">'>]

#8、帶變數的xpath
>>> response.xpath('//div[@id=$xxx]/a/text()',xxx='images').extract_first()
'Name: My image 1 '
>>> response.xpath('//div[count(a)=$yyy]/@id',yyy=5).extract_first() #求有5個a標簽的div的id
'images'
View Code

https://docs.scrapy.org/en/latest/topics/selectors.html

七 Items

https://docs.scrapy.org/en/latest/topics/items.html

八 Item Pipeline

#一:可以寫多個Pipeline類
#1、如果優先順序高的Pipeline的process_item返回一個值或者None,會自動傳給下一個pipline的process_item,
#2、如果只想讓第一個Pipeline執行,那得讓第一個pipline的process_item拋出異常raise DropItem()

#3、可以用spider.name == '爬蟲名' 來控制哪些爬蟲用哪些pipeline

二:示範
from scrapy.exceptions import DropItem

class CustomPipeline(object):
    def 	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • http://blog.csdn.net/u011475134/article/details/70198533 原出處 在上一篇文章《使用python-aiohttp爬取網易雲音樂》中,我們給自己的微信公眾號添加了線上點歌的功能,這次我們再增加一個新聞瀏覽的功能。由於我平時瀏覽新聞用的是今日頭條, ...
  • 1、<?php echo count(strlen(“http://php.net”)); ?>的執行結果是? 答案:1 講解:count(var)是用來統計數組或對象的元素個數的。當var是null或者空數組時,結果為0。如果var是普通變數,則返回1。正常情況下返回var中的元素或屬性個數。 2 ...
  • 按鍵值的降序排序 按值的降序排序,如果值相同則按鍵值的字母順序 要註意這個問題: 不能把map.entrySet()直接強轉成List<Entry<Character,Integer>> 需要用new ArrayList()的構造,即放在參數中 ...
  • 不想下班之後待在只有自己一個人的小房間了自怨自艾,懷疑人生。所以,我選擇python 為什麼是它? 有過那麼一段想法,哈哈哈哈哈哈哈額。。。世界沒後悔藥吃,現在也不遲。保持前進就好。 給自己兩年時間。 為什麼是兩年? 有時間限制,會更有動力。 你拿什麼跟別人電腦基礎良好,大學專業課程四年的人比? ...
  • 獻上代碼,不成敬意: ~~~~ include include int main() { int i = 0; if(fork()) i++; if(fork()) i++; if(fork()) i++; printf("i = %d\n",i); return 0; } ~~~~ 一段看似簡單但 ...
  • 今天正在看書,老鐵給我發來一道面試題。 初看這道題,我覺得是送分題。嘴角上揚寫出一行命令: 仔細看了一眼,這道題說的是將字元刪掉,好險中了他的招,然後改了一下。 看了一下,沒毛病,遂發給老鐵,老鐵瞬即回覆:非也,非也。這種難度豈敢請教愚兄。此題有陷阱,若是生成列表推導或是生成器表達式抑或是map,f ...
  • 元組(tuple):戴上了枷鎖的列表 元組與列表非常相似但是元組內元素的類型相同,且元組內的元素不能修改 1、創建元組的方法 與列表不同創建元組大部分情況下是用小括弧,例如 也可以不用小括弧,例如 因此創建元組的關鍵在於“逗號”,在創建單個元素的元組時應註意: >>> 8*8,(64,)>>> 8* ...
  • 2016年底的時候阿裡巴巴公開了其在內部使用的Java編程規範。隨後進行了幾次版本修訂,目前的版本為v1.0.2版。下載地址可以在其官方社區-雲棲社區https://yq.aliyun.com/articles/69327找到。 筆者作為一名有數年工作經驗的Java程式員,仔細研讀了這份手冊,覺得其 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...