上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页
摘要: import asyncio import aiohttp CONCURRENCY = 5 URL = 'https://www.baidu.com' semaphore = asyncio.Semaphore(CONCURRENCY) session = None async def scrape 阅读全文
posted @ 2025-12-28 11:52 chenlight 阅读(6) 评论(0) 推荐(0)
摘要: 在 Python 中,如果你定义了一个 协程函数(coroutine function),例如: async def funa(): ... 那么 funa() 本身并不会立即执行,而是返回一个 协程对象(coroutine object)。要真正“启动”或“运行”这个协程函数,有以下几种常见方式: 阅读全文
posted @ 2025-12-28 10:51 chenlight 阅读(2) 评论(0) 推荐(0)
摘要: import asyncio import aiohttp import time start = time.time() async def get(url): session = aiohttp.ClientSession() response = await session.get(url) 阅读全文
posted @ 2025-12-28 09:59 chenlight 阅读(11) 评论(0) 推荐(0)
摘要: import asyncio import requests async def request(): url = 'https://www.baidu.com' status = requests.get(url) # 同步阻塞的GET请求 print("This is :",status) pr 阅读全文
posted @ 2025-12-26 17:24 chenlight 阅读(2) 评论(0) 推荐(0)
摘要: import json import requests import logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s' ) INDEX_URL = 'h 阅读全文
posted @ 2025-12-26 15:09 chenlight 阅读(3) 评论(0) 推荐(0)
摘要: 一、创建MySql数据库 import pymysql db = pymysql.connect(host='localhost',user='root',password='root',port=3306) cursor = db.cursor() cursor.execute('SELECT V 阅读全文
posted @ 2025-12-25 22:18 chenlight 阅读(3) 评论(0) 推荐(0)
摘要: import json data = [{ 'name': 'Bob', 'gender': 'male', 'birthday': '1992-10-18' }] with open('data.json', 'w', encoding='utf-8') as file: file.write(j 阅读全文
posted @ 2025-12-25 14:52 chenlight 阅读(5) 评论(0) 推荐(0)
摘要: 先看一下书中代码原文: 按照原书中代码输入后,错误提示如下: I:\python\text文本存储.py:19: SyntaxWarning: invalid escape sequence '\d' published_at = re.search('(\d{4}-\d{2}-\d{2})',pu 阅读全文
posted @ 2025-12-25 12:52 chenlight 阅读(3) 评论(0) 推荐(0)
摘要: 以下是 CSS 选择器(CSS Selectors) 的完整规则汇总,适用于网页开发、爬虫(如 PyQuery、BeautifulSoup、Scrapy、Selenium 等)以及前端样式编写。 一、基础选择器(Basic Selectors) 选择器示例含义**通配符:匹配所有元素标签名div, 阅读全文
posted @ 2025-12-25 12:00 chenlight 阅读(64) 评论(0) 推荐(0)
摘要: Python 中的协程(Coroutine)是一种可以暂停和恢复执行的函数,用于实现异步编程。它在 I/O 密集型任务中非常有用,比如网络请求、文件读写等,可以在等待时切换到其他任务,从而提高程序效率。 一、基本概念 协程 vs 线程:协程是用户态的轻量级“线程”,由程序员控制调度(协作式多任务), 阅读全文
posted @ 2025-12-25 11:34 chenlight 阅读(16) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页