03 2022 档案
摘要:通过 Traceback 能得知运行异常的位置、原因 当程序没有捕获异常、运行异常时 会自动调用 Traceback 进行异常回溯 捕获异常 当程序捕获异常时 不会自动调用 Traceback 进行异常回溯 def run(): try: print('Before') print(1 / 0) p
阅读全文
摘要:将当前环境中已安装的三方库及对应版本 输出到文本中 pip freeze > requirements.txt 卸载当前环境中所有安装的库 pip uninstall -r requirements.txt -y 安装文本中 对应版本的所有三方库 pip install -r requirement
阅读全文
摘要:安装 pip install scrapy 导入 from scrapy.selector import Selector 待提取文本 content = """ <table class="tab"> <tr class="cdf"> 1<a>tr下的第一个a标签</a>2 3<td class=
阅读全文
摘要:方法一 先按 Ctrl + F8:Deactivate breakpoints 禁用所有断点 再按 F8:Resume script execution 恢复脚本执行 这种情况下,自己添加的断点也会被禁用 方法二 在 debugger 所在行的行号(数字)上,右键选择Add conditional
阅读全文
摘要:关闭不安全请求警告 import urllib3 urllib3.disable_warnings() import requests import urllib3 urllib3.disable_warnings() response = requests.get('https://www.bai
阅读全文
摘要:导入 import pickle 转换 data = [{'title': 't1', 'url': 'one'}, {'title': 't2', 'url': 'two'}] data_dumps = pickle.dumps(data) print(type(data_dumps)) # <c
阅读全文
摘要:Python 使用正则 清除字符串中除了 <sub>...</sub> 和 <sup>...</sup> 以外的所有 html 标签 指定标签内无其它标签 import re def sub_replace(match_obj): # print(type(match_obj), match_obj
阅读全文
摘要:IP 查看 http://ip111.cn http://httpbin.org/get http://test.abuyun.com https://ip.cn https://ip.tool.lu https://ipapi.co/json https://www.ip138.com https
阅读全文
摘要:Headers General Request URL:请求链接 Request Method:请求方式 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods Status Code:状态码(可自定义) https://www.runoo
阅读全文
摘要:当队列为空时,执行get(),不会报异常 会进入阻塞状态,直到队列中有东西可取为止 from queue import Queue taskQueue = Queue() taskQueue.put('queue task 1') print(f'队列长度:{taskQueue.qsize()}')
阅读全文
摘要:请求 视频地址 和 M3U8 地址 的时候,http 请求中会带上自定义的请求头 // 全局拦截器 videojs.Vhs.xhr.beforeRequest = function (options: any) { let headers = options.headers || {}; heade
阅读全文
摘要:import os # os.path.split 分割路径 path1 = r'e:\tool\read.txt' print(os.path.split(path1)) # ('e:\\tool', 'read.txt') print(os.path.splitext(path1)) # ('e
阅读全文
摘要:单进程单线程 import time def production(): """ 间隔一秒,模拟一秒生产一个任务,生产10个任务 :return: 生产完毕,返回需要消费的任务 """ _tasks = 0 while _tasks < 10: time.sleep(1) _tasks += 1 p
阅读全文
摘要:Module 模块 export:导出模块 point.ts 文件的内容(导出) interface IPoint{ num:number printNum:() => void; } // 关键字 export 导出模块 export class Point implements IPoint{
阅读全文