Friday, December 31, 2021

[python 反爬蟲原理與繞過實戰] 第三方庫安裝

Requests (http 請求庫)

pip install requests

Selenium (web 應用程序測試工具)

pip install selenium

瀏覽器驅動

ChromeDriver

查詢版本 

版本 1.33.106 Chromium: 96.0.4664.110 (正式版本) (64 位元)

下載並執行

sudo mv chromedriver /usr/bin/

Firefox
geckodriver --version

Splash 異步 JavaScript 渲染服務

從 dockerHub 中拉取 Splash

sudo docker run -it -p 8050:8050 scrapinghub/splash

http://localhost:8050

Puppeteer (Google 出的 Node.js 庫)

pip install pyppeteer


安裝

https://ithelp.ithome.com.tw/articles/10233316

https://github.com/tesseract-ocr/tesseract

https://officeguide.cc/tesseract-open-source-ocr-engine-tutorial-examples/






cuDNN (深度神經網路庫)

[python 反爬蟲原理與繞過實戰] 安裝 docker

安裝 docker (參考)

sudo apt-get update

1. 安裝允許 apt 通過 https 協議使用存儲庫

sudo apt-get install apt-transport-https

sudo apt-get install ca-certificates

sudo apt-get install curl

sudo apt-get install gnupg-agent

sudo apt-get install software-properties-common

2. 添加 docker 官方的 gpg 密鑰

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

確認密鑰添加成功

abc@ubuntu:/extspace/src$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]

      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88

uid           [ unknown] Docker Release (CE deb) <docker@docker.com>

sub   rsa4096 2017-02-22 [S]

添加 Stable 版本的存儲庫

sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

or 

echo \

  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \

  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安裝 Docker CE

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

確認

abc@ubuntu:/extspace/src$ sudo docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

[python 反爬蟲原理與繞過實戰] 架設 Streamboat

sudo docker pull registry.cn-hangzhou.aliyuncs.com/steamboat/steamboat:sp1

sudo docker pull registry.cn-hangzhou.aliyuncs.com/steamboat/steamboat:sp2

sudo docker pull registry.cn-hangzhou.aliyuncs.com/steamboat/steamboat:sp3


abc@ubuntu:/extspace/src/python_bug$ sudo docker images

REPOSITORY                                              TAG       IMAGE ID       CREATED         SIZE

hello-world                                             latest    d1165f221234   10 months ago   13.3kB

registry.cn-hangzhou.aliyuncs.com/steamboat/steamboat   sp1       9b5cc6bd42d0   2 years ago     111MB

registry.cn-hangzhou.aliyuncs.com/steamboat/steamboat   sp3       5c75ec9ef2b6   2 years ago     936MB

registry.cn-hangzhou.aliyuncs.com/steamboat/steamboat   sp2       0487eb7998d9   2 years ago     936MB

開 port

sp1:80 8090 8205 8207
sp2:8202
sp3:8206

運行 sp2

sudo docker run -d -p 8202:8202 0487eb7998d9


http://192.168.168.1:8202/

[python 反爬蟲原理與繞過實戰] 安裝環境

安裝 python3

安裝 docker

架設 Streamboat

第三方庫安裝

Wednesday, December 29, 2021

[JavaScript] preventDefault, stopPropagation

event.stopPropagation() 為了阻止事件繼續冒泡

event.preventDefault() 停止事件的默認動作

stopImmediatePropagation() 讓其他同一層級的 listener 也不要被執行

[JavaScript] input 停止輸入 key

 input 停止輸入 key

主要加上 evt.preventDefault()

=============================================

  checkSkipKey(evt) {

    let time = new Date().getTime()

    let key = evt.keyCode


    if((REPEAT_KEY_TIME > (time - this._timeStamp)) && (key == this._previousKey)) {

      this.log.show(this.debug_info,'skip key time - this._timeStamp:', time - this._timeStamp)

      return true

    }

    this._previousKey = key

    this._timeStamp = time

    return false

  }


    if(this.checkSkipKey(evt)) {

      if (!!evt) {

        evt.preventDefault()

        if(typeof evt.stopImmediatePropagation === 'function') {

          evt.stopImmediatePropagation()

        } else {

          evt.stopPropagation()

        }

      }

      return

    }

=============================================

C 指標介紹

简化一些 C++ 编程任务的执行,还有一些任务,如动态内存分配,没有指针是无法执行的

& 不要都念成 and,涉及指標操作的時候,要讀為 “address of”

在 開發工具和規格標準 篇提過參考第一手資料的重要性,以下 ISO/IEC 9899 (簡稱 “C99”)和指標相關的描述:

  • 規格書 (PDF) 搜尋 “object”,共出現 735 處

    • 搜尋 “pointer”,共出現 637 處。有趣的是,許多教材往往不談 object,而是急著談論 pointer,殊不知,這兩者其實就是一體兩面
    • object != object-oriented
      • 前者的重點在於「資料表達法」,後者的重點在於 “everything is object”
    • C11 (ISO/IEC 9899:201x) / 網頁版
  • & 不要都念成 and,涉及指標操作的時候,要讀為 “address of”

    • C99 標準 [6.5.3.2] Address and indirection operators 提到 ‘&’ address-of operator
  • C99 [3.14] object

    • region of data storage in the execution environment, the contents of which can represent values
    • 在 C 語言的物件就指在執行時期,資料儲存的區域,可以明確表示數值的內容
    • 很多人誤認在 C 語言程式中,(int) 7 和 (float) 7.0 是等價的,其實以資料表示的角度來看,這兩者截然不同,前者對應到二進位的 “111”,而後者以 IEEE 754 表示則大異於 “111”
  • C99 [6.2.5] Types

    • A pointer type may be derived from a function type, an object type, or an incomplete type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type T is sometimes called ‘‘pointer to T’’. The construction of a pointer type from a referenced type is called ‘‘pointer type derivation’’.

    注意到術語!這是 C 語言只有 call-by-value 的實證,函式的傳遞都涉及到數值
    這裡的 “incomplete type” 要注意看,稍後會解釋。要區分 char [] 和 char *

    • Arithmetic types and pointer types are collectively called scalar types. Array and structure types are collectively called aggregate types.

    注意 “scalar type” 這個術語,日後我們看到 ++--+=-= 等操作,都是對 scalar (純量)

    [來源] 純量只有大小,它們可用數目及單位來表示(例如溫度 = 30oC)。純量遵守算數和普通的代數法則。注意:純量有「單位」(可用 sizeof 操作子得知單位的「大小」),假設 ptr 是個 pointer type,對 ptr++ 來說,並不是單純 ptr = ptr + 1,而是遞增或遞移 1 個「單位」

    • An array type of unknown size is an incomplete type. It is completed, for an identifier of that type, by specifying the size in a later declaration (with internal or external linkage). A structure or union type of unknown content is an incomplete type. It is completed, for all declarations of that type, by declaring the same structure or union tag with its defining content later in the same scope.

    這是 C/C++ 常見的 forward declaration 技巧的原理,比方說我們可以在標頭檔宣告 struct GraphicsObject; (不用給細部定義) 然後 struct GraphicsObject *initGraphics(int width, int height); 是合法的,但 struct GraphicsObject obj; 不合法

    • Array, function, and pointer types are collectively called derived declarator types. A declarator type derivation from a type T is the construction of a derived declarator type from T by the application of an array-type, a function-type, or a pointer-type derivation to T.

    這句話很重要,貌似三個不相關的術語「陣列」、「函式」,及「指標」都歸類為 derived declarator types,讀到此處會感到驚訝者,表示不夠理解 C 語言


int main() {
    typedef void (*funcptr)();
    (* (funcptr) (void *) 0)();
}

main:
        push    rax
        xor     eax, eax
        call    rax
        xor     eax, eax
        pop     rdx
        ret

Segmentation fault (core dumped)

我去呼叫地址為 0 的函數

0這個地址不是使用者層級可以呼叫

Reference:
https://hackmd.io/@sysprog/c-pointer
1:18:08

C 指標入門 考試3

What is the last (int) doing? 

Consider the signal() function from the C standard:

void ( *signal(int sig, void (*handler)(int)) ) (int);


The whole thing declares a function called signal:

  • signal takes an int and a function pointer
    • this function pointer takes an int and returns void
  • signal returns a function pointer
    • this function pointer takes an int and returns a void

That's where the last int comes in.


        signal                                          -- signal

        signal(                               )         -- is a function

        signal(    sig                        )         -- with a parameter named sig

        signal(int sig,                       )         --   of type int

        signal(int sig,        handler        )         -- and a parameter named handler

        signal(int sig,       *handler        )         --   which is a pointer

        signal(int sig,      (*handler)(   )) )         --   to a function

        signal(int sig,      (*handler)(int)) )         --   taking an int parameter

        signal(int sig, void (*handler)(int)) )         --   and returning void

       *signal(int sig, void (*handler)(int)) )         -- returning a pointer

     ( *signal(int sig, void (*handler)(int)) )(   )    -- to a function

     ( *signal(int sig, void (*handler)(int)) )(int)    --   taking an int parameter

void ( *signal(int sig, void (*handler)(int)) )(int);   --   and returning void


You can use the spiral rule to make sense of such declarations, or the program cdecl(1)


If you write:

typedef void (*SignalHandler)(int signum);


then you can instead declare signal() as:

extern  SignalHandler signal(int signum, SignalHandler handler);

C 指標入門 考試2

 科技公司面試題:

void **(*d) (int &, char **(*)(char *, char **));

上述宣告的解讀:

  • d is a pointer to a function that takes two parameters:
    • a reference to an int and
    • a pointer to a function that takes two parameters:
      • a pointer to a char and
      • a pointer to a pointer to a char
    • and returns a pointer to a pointer to a char
  • and returns a pointer to a pointer to void

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能