diff --git a/README.md b/README.md index 816452c79d8f2321606f65c2f66be05facdabf51..1baffde32db329726a3447a1d90f989168f345d0 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,6 @@ # 存放 shell学习笔记 /shell_note + +# 存放git学习笔记 +/git_note diff --git a/git_note/git_txt.py b/git_note/git_txt.py new file mode 100644 index 0000000000000000000000000000000000000000..8ff5f8572a5d2f3bd283dc4b7f8e22597ab613bc --- /dev/null +++ b/git_note/git_txt.py @@ -0,0 +1,5 @@ +# 修改前数据 + +print(f"------------------------------") + + diff --git a/python_module_note/numba_module.py b/python_module_note/numba/numba_module.py similarity index 100% rename from python_module_note/numba_module.py rename to python_module_note/numba/numba_module.py diff --git a/python_module_note/numba_module1.py b/python_module_note/numba/numba_module1.py similarity index 54% rename from python_module_note/numba_module1.py rename to python_module_note/numba/numba_module1.py index 18ff2844f8949e67f070dbdcf19bcc1dc8291b59..499c605f494e1073a5e382b1637b46c69791387f 100644 --- a/python_module_note/numba_module1.py +++ b/python_module_note/numba/numba_module1.py @@ -1,14 +1,15 @@ import time -from numba import jit +from numba import njit +@njit def foo(x, y): - tt = time.time() s = 0 for i in range(x, y): s += i - print('Time used: {} sec'.format(time.time() - tt)) return s +t1 = time.time() print(foo(1, 100000000)) +print('Time used: {} sec'.format(time.time() - t1)) diff --git a/python_module_note/numba/numba_module2.py b/python_module_note/numba/numba_module2.py new file mode 100644 index 0000000000000000000000000000000000000000..1cfa80908366093a5174b97669a9a303315bbd6c --- /dev/null +++ b/python_module_note/numba/numba_module2.py @@ -0,0 +1,15 @@ +from numba import jit +import numpy as np + +x = np.arange(100).reshape(10, 10) + + +@jit(nopython=True) # Set "nopython" mode for best performance, equivalent to @njit +def go_fast(a): # Function is compiled to machine code when called the first time + trace = 0.0 + for i in range(a.shape[0]): # Numba likes loops + trace += np.tanh(a[i, i]) # Numba likes NumPy functions + return a + trace # Numba likes NumPy broadcasting + + +print(go_fast(x)) diff --git a/python_module_note/pyppeteer/pyppeteer_02.py b/python_module_note/pyppeteer/pyppeteer_02.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..090fdfa0188ea41ef1c9b9c29aab97e9a8ab955f 100644 --- a/python_module_note/pyppeteer/pyppeteer_02.py +++ b/python_module_note/pyppeteer/pyppeteer_02.py @@ -0,0 +1,63 @@ +#!/user/bin/python +# -*- coding:UTF-8-*- + +""" +@time:2022/01/20 +""" + +import asyncio +from pyppeteer import launcher, launch + +# 去除浏览器自动化参数,隐藏自动化工具特征 +launcher.DEFAULT_ARGS.remove("--enable-automation") + +from setting import * + + +async def main(): + start_parm = { + 'executablePath': dir_chrome, + 'headless': False, + 'dumpio': True, + 'ignoreHTTPSErrors': False, + 'args': [ + '--disable-infobars', # 关闭自动化提示框 + '--no-sandbox', # 关闭沙盒模式 + # '--window-size=1920,1080', # 窗口大小 + '--start-maximized', # 窗口大小 + ] + } + # 创建浏览器对象 + browser = await launch(**start_parm) + # 创建一个页面对象 + page = await browser.newPage() + # 设置ua + await page.setUserAgent( + 'Mozilla/5.0 (Windows NT 100; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' + ) + # 修改navigator.webdriver检测 + # 各种网站的检测js是不一样的,这是比较通用的。有的网站会检测运行的电脑运行系统,cpu核心数量,鼠标运行轨迹等等。 + # 反爬js + js_text = """ + () =>{ + Object.defineProperties(navigator,{ webdriver:{ get: () => false } });window.navigator.chrome = { runtime: {}, }; + Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] }); + Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); + } + """ + # 本页刷新后值不变,自动执行js + await page.evaluateOnNewDocument(js_text) + # 打开一个页面 + await page.goto('https://www.baidu.com') + # await page.goto('https://www.httpbin.org/headers') + + await asyncio.sleep(3) + + page_text = await page.content() + + print(page_text) + + await browser.close() + + +asyncio.get_event_loop().run_until_complete(main()) diff --git a/setting.py b/setting.py new file mode 100644 index 0000000000000000000000000000000000000000..7c674fa68ed404e197c664c85ed9a96e4b6ad9f4 --- /dev/null +++ b/setting.py @@ -0,0 +1,3 @@ + + +dir_chrome = '/snap/chromium/1864/usr/lib/chromium-browser/chrome'