07 2021 档案

摘要:开启8个线程,每个线程开启8个协程 计算数的平方 代码: import gevent.pool import gevent.monkey gevent.monkey.patch_all() import concurrent.futures def go(n): return n*n def gev 阅读全文
posted @ 2021-07-06 09:59 山鬼谣` 阅读(296) 评论(0) 推荐(0) 编辑
摘要:计算一组数的平方 代码: import gevent.pool import gevent.monkey gevent.monkey.patch_all() def go(n): return n*n if __name__ == "__main__": mypool = gevent.pool.P 阅读全文
posted @ 2021-07-06 09:55 山鬼谣` 阅读(226) 评论(0) 推荐(0) 编辑
摘要:计算 1-200 的平方,数据长这样:[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],...,[180, 181, 182, 183, 184, 185, 186, 187, 188, 189],[1 阅读全文
posted @ 2021-07-04 10:51 山鬼谣` 阅读(216) 评论(0) 推荐(0) 编辑
摘要:简单来说,正则表达式的 .*? 可以匹配任意字符串,例子如下: 数据的结构长这样: 代码: #coding=utf-8 import re from bs4 import BeautifulSoup mystr2 = '<ul><li class="" data-rid="1"><a class=" 阅读全文
posted @ 2021-07-03 17:54 山鬼谣` 阅读(2519) 评论(0) 推荐(0) 编辑
摘要:分布式:让多台计算机同时干活 计算1,2,3,...,10000 的平方数 原理: 代码(服务器): #服务器端 import multiprocessing.managers #分布式进程管理器 import queue #队列 task_queue = queue.Queue() #任务队列(发 阅读全文
posted @ 2021-07-03 16:21 山鬼谣` 阅读(410) 评论(0) 推荐(0) 编辑
摘要:开启10个进程,每个进程开10个线程 import concurrent.futures def go(n): return n*n def processgo(list): with concurrent.futures.ThreadPoolExecutor(10) as pool: # 开启10 阅读全文
posted @ 2021-07-03 11:05 山鬼谣` 阅读(350) 评论(0) 推荐(0) 编辑
摘要:xpath是解析网页的另一种方法,该方法最大的好处在于可以直接复制路径。 复制粘贴得到路径:/html/body/div[2]/div[6]/div[1]/div/ul/li[1]/a[2] #导入模块并爬取页面 import requests from lxml import etree url 阅读全文
posted @ 2021-07-02 20:06 山鬼谣` 阅读(311) 评论(0) 推荐(0) 编辑
摘要:BeautifulSoup是解析网页的基本库之一。简单用法如下: 这里选取class为“nav-list site-nav fl”的div标签,如上图所示 from bs4 import BeautifulSoup div = '<div class="nav-list site-nav fl">< 阅读全文
posted @ 2021-07-02 17:31 山鬼谣` 阅读(153) 评论(0) 推荐(0) 编辑
摘要:只有名称不同,其他完全一样 1、线程池: import concurrent.futures def go(n): return n*n if __name__ == "__main__": list = [1,2,3,4,5,6,7,8,9,10,11,12] with concurrent.fu 阅读全文
posted @ 2021-07-02 16:49 山鬼谣` 阅读(145) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示