python
小牛头#
随静写码!
展开
-
字典的列表,如何把其中 key 相同的字典的 value 合并一下
字典的列表,如何把其中 key 相同的字典的 value 合并一下原创 2023-03-01 17:05:14 · 352 阅读 · 1 评论 -
python for循环获取网站页数
【代码】python for循环获取网站页数。原创 2023-01-16 14:46:30 · 568 阅读 · 0 评论 -
pandas groupby 分组之后直接输出
pandas分组之后直接输出原创 2022-11-17 15:15:07 · 1437 阅读 · 0 评论 -
输入两个日期,获取月份的第一天和最后一天
python 月份最早一天最晚一天获取原创 2022-10-26 17:27:40 · 151 阅读 · 0 评论 -
用户行为分析-阿里日志服务
日志埋点存储的地方是阿里云的sls,本项目使用的是python接入sls日志服务导出日志。原创 2022-08-22 16:04:17 · 431 阅读 · 0 评论 -
列表字典去重
代码】列表字典去重。原创 2022-08-18 19:23:30 · 85 阅读 · 0 评论 -
pandas 用户行为-用户时间分类
用户行为分类原创 2022-08-15 17:13:55 · 304 阅读 · 0 评论 -
sqlalchemy连接clickhouse批量插入数据
sqlalcgemy连接clickhouse原创 2022-08-11 18:30:39 · 2231 阅读 · 0 评论 -
pyecharts 关系图
pyecharts关系图原创 2022-08-08 17:31:17 · 570 阅读 · 0 评论 -
python 随机获取时间,时间戳和时间的转换
代码】python随机获取时间,时间戳和时间的转换。原创 2022-07-27 14:39:13 · 964 阅读 · 0 评论 -
python字典有类似相同的key分为同一组 | python根据特定的前缀分组
# def getResult_1(l): res = [] keys = set([item[i]['key'] for item in l for i in range(0, len(item))]) for ip in keys: tmp = [] for ite in l: for i in range(0, len(ite)): if ip == ite[i]['key']:原创 2022-04-01 20:10:10 · 1034 阅读 · 0 评论 -
python 爬虫http2
查看是否是http2请求呢?打开火狐浏览器使用requests爬虫就会失败,所以得使用httpx包import httpxclient = httpx.Client(http2=True)# 之后的使用方式和requests一样# postresult = client.post(url,json=data, headers=headers, cookies=cookies ).json()# getresult = cl原创 2022-03-18 15:13:13 · 4212 阅读 · 0 评论 -
python 邮箱
# coding=utf-8from email.parser import Parserfrom email.header import decode_headerfrom email.utils import parseaddrimport poplibimport smtplibfrom email.mime.text import MIMETextclass ReceiveEmail: ''' 接收信息 ''' # 输入邮件地址, 口令和POP3服务原创 2022-03-17 14:58:55 · 330 阅读 · 0 评论 -
Echarts 生成地图html
Echart原创 2022-03-17 11:30:23 · 1895 阅读 · 1 评论 -
英文日期转换数字日期
def change_time(input_time): year = input_time.split(',')[-1].strip() month = str(list(calendar.month_abbr).index(input_time.split(' ')[0])) if int(month) < 10: month = '0' + str(month) day = int(input_time.split(',')[0].split(原创 2022-03-05 10:22:21 · 1071 阅读 · 0 评论 -
pandas 多个文件merge合并
files = os.listdir(dirs) from functools import reduce app=[] for file in files: result_file = os.path.join(dirs, file) df = pd.read_csv(result_file) app.append(df) df_final = reduce(lambda left, right: pd.merge(lef原创 2022-03-01 17:58:25 · 1038 阅读 · 0 评论 -
os.listdir数字乱序万能解法
def get_order(get_file): files = os.listdir(get_file) c = [] for f in files: f = re.sub("\D", "", f) c.append(f) c_1 = sorted(list(map(int, c))) new_files = [('order_' + str(i) + '.csv') for i in c_1] print(ne原创 2021-11-06 17:19:32 · 141 阅读 · 0 评论 -
pandas 链接MySQL正确关闭
若要真正关闭链接,则需要采用:conn.dispose()conn = create_engine('mysql+pymysql:user:passwd@host:port/db?charset=etf-8')try: with con: dataIn2File.to_sql(table_name,con=conn,if_exists='append',index=False)except Exception as ee: logger.error("fileToMys转载 2021-08-13 16:35:40 · 954 阅读 · 0 评论 -
爬虫 requests ValueError: check_hostname requires server_hostname
解决方案:pip3 install urllib3==1.25.11原创 2021-06-24 12:12:03 · 1779 阅读 · 2 评论 -
selenium下载文件到指定位置
self.option = ChromeOptions()# self.option.add_argument("--user-data-dir=" + r"C:/Users/EDZ/AppData/Local/Google/Chrome/User Data") self.option.add_experimental_option('excludeSwitches', ['enable-automation']) self.option.add_experimental_option('useAut原创 2021-06-23 17:11:52 · 2891 阅读 · 1 评论 -
MYSQL 修改路径后 my.ini 要另存为ANSI编码
MYSQL 修改路径后 my.ini 要另存为ANSI编码原创 2021-04-12 10:07:42 · 1611 阅读 · 0 评论 -
python爬虫实时保存数据,csv格式
话不多说,直接上代码。import csvfile_path 为保存的路径,需要携带.csv后缀。urt_8_sig 是一个编码,使用该编码后,不用在另存为txt转换utf-8格式,直接打开,不会乱码。replace(’\x00’, ‘’) 是防止需要保存的字符出现不可识别乱码。head 是一个列表 [‘A’,‘B’,‘C’,‘D’]value 是一个列表 [1,2,3,4]保存的时候,表头只会保存一次,程序会自我辨别,所以不用担心。with open(file_path, 'a', enc原创 2021-04-08 16:27:16 · 1171 阅读 · 0 评论 -
python selenium 向标签中写入内容
data = 'document.getElementById("returnName1").innerHTML="百度" 'browser.execute_script(data)原创 2021-04-01 13:25:32 · 858 阅读 · 0 评论 -
selenium获取cookies转换后转给requests
from selenium import webdriverimport timeimport requestsdriver = webdriver.Chrome()#因为浏览器中可能会有别的网址的cookies#为了防止污染,清空cookiedriver.delete_all_cookies()#访问test_url,获取该网站的cookiesdriver.get(test_url)#获取cookies cookie_list = [item["name"] + "=" + i原创 2021-04-01 11:10:54 · 1945 阅读 · 0 评论 -
Python TypeError: argument of type ‘NoneType‘ is not iterable 报错解决
在python上使用if a=b:elif a=c:等判断语句的时候,如果没有加入else:的话,就会返回Noneelse:解决办法就是判断语句一定要全面。原创 2021-03-23 11:18:39 · 16164 阅读 · 1 评论 -
seleniu下载pdf文件
话不多说,直接上代码from selenium import webdriverfrom selenium.webdriver import ChromeOptionsoptions = webdriver.ChromeOptions()options.add_experimental_option('prefs', { #"download.default_directory": 'D:/1pdf/test', "download.prompt_for_download": F原创 2021-03-22 11:36:22 · 384 阅读 · 0 评论 -
pandas读取文件和open读取文件对比速度
pandas读取文件starts=time.time()for file in files[:1]: print(file) file_paths = os.path.join(root, file) print(file_paths) list2=[] # with open(file_paths,'r') as f: # for row in f: # list2 = [row.split(',')[line] for原创 2021-01-22 15:24:32 · 2606 阅读 · 0 评论 -
python 多列表交集处理和sorted函数字符串列表排序问题
b1=['0', '1','3', '4', '5', '6', '7', '8', '9', '10','1000', '11', '13', '15', '16', '18', '19', '20', '22', '24', '25', '26', '27', '28', '29', '30', '31', '33', '34', '35', '36', '37']b2=[['0', '1','3', '4', '5', '6','1000'],['3','4', '5', '6', '7', '8原创 2021-01-14 18:06:46 · 199 阅读 · 0 评论 -
实时显示csv数据
with open('sh_text.csv', 'a', encoding='utf_8_sig', newline='') as csvfile: writer = csv.writer(csvfile) with open('sh_text.csv', 'r', encoding='utf_8_sig', newline='') as f: reader = csv.reader(f) if not [row for row in reader]原创 2020-12-04 11:39:02 · 369 阅读 · 0 评论 -
获取指定时间段日期
import datetimedef get_every_day(begin_date_str, end_date_str): date_list = [] begin_date = datetime.datetime.strptime(begin_date_str, "%Y-%m-%d") end_date = datetime.datetime.strptime(end_date_str, "%Y-%m-%d") while begin_date <= end_原创 2020-11-25 11:12:38 · 242 阅读 · 0 评论 -
json标准化解析
针对有callback的一些标准jsonimport reimport jsondef loads_jsonp(_jsonp): try: return json.loads(re.match(".*?({.*}).*",_jsonp,re.S).group(1)) except: raise ValueError('Invalid Input')原创 2020-11-24 13:36:45 · 667 阅读 · 0 评论 -
selenium缓慢下拉加定位下拉
self.browser.get(self.INDEX_URL)js = "return action=document.body.scrollHeight"height = 0new_height = self.browser.execute_script(js)while height < new_height: # 将滚动条调整至页面底部 for i in range(height, new_height, 100): self.browser.execu原创 2020-11-23 09:50:48 · 517 阅读 · 1 评论 -
书写 PyQt5 可视化界面爬虫项目的需要笔记
1-使用Qthring多线程进行书写from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal首先爬虫类需要继承QObject类在爬虫里定义信号将每个爬虫定义为信号槽函数在爬虫函数结束时发送信号在UI界面里,使用信号链接槽,在槽里定义QTextBrowser的输出下面为信号链接的各个槽连接爬虫和线程,运行程序from PyQt5.QtCore import QCoreApplication, QMetaObject, Qt,原创 2020-11-11 13:44:46 · 427 阅读 · 0 评论 -
python to_csv追加DataFrame 表头重复问题
当多个带表头的DataFrame使用to_csv追加时,表头重复的问题。全部显示pd.options.display.max_columns = Nonepd.options.display.max_rows = None例如:追加的时候,判断文件是否存着,如果不存在则添加表头,否则添加表头if not os.path.exists('result.csv'): data.to_csv('result.csv',encoding='utf_8_sig',mode='a',index=原创 2020-09-18 11:10:33 · 6272 阅读 · 4 评论 -
python csv模块 防止重复写入标题
```python#newline的作用是防止每次插入都有空行 with open("test.csv", "a+", newline='') as csvfile: writer = csv.writer(csvfile) #以读的方式打开csv 用csv.reader方式判断是否存在标题。 with open("test.csv", "r", newline="") as f: reader = csv.reader(f.原创 2020-09-17 09:44:20 · 1237 阅读 · 0 评论 -
python3 pandas 的一些写法
re_data_text=['2013-01-04 09:25:00', '2013-01-04 09:26:00', '2013-01-04 09:27:00', '2013-01-04 09:28:00', '2013-01-04 09:29:00', '2013-01-04 09:30:00']app=[] for re_time_text in re_data_text: time_text=str原创 2020-06-03 16:01:40 · 228 阅读 · 0 评论 -
大众点评数据爬虫,破解反爬虫(学习使用)
大众点评不同的网页处理的反爬是不一样的。http://www.dianping.com/shop/k9oYRvTyiMk4HEdQ/review_all/p2URL中带了review_all和没有带的区别是很大的。首先先讲带review_all的URL,也就是需要全部评论的URL具体的字体映射思想 点这里首先先使用加载 //3plus…的css文件,可以得到一个很全的css位置样式。...原创 2020-04-29 15:21:45 · 6389 阅读 · 8 评论 -
python3多进程阻塞与非阻塞快速理解
python多进程阻塞和非阻塞非阻塞: (不需要等待)。简单来说就是开启几个进程就同时运行几个进程。比如下面程序,开启3个进程,那么程序一运行的时候立马执行3个进程同时调用function方法,不需要等待进程1执行完在执行进程2。from multiprocessing import Lock, Poolimport timedef function(index): pr...原创 2020-03-31 12:10:17 · 8401 阅读 · 0 评论