从零基础到三个月攒下笔记送个大家!希望大家多多支持!
昨天跟大佬交流下,说要多写写博客。可没有这个耐心,平常都是记笔记,从来没写博客习惯。好了,废话不多说。直接上笔记!
python 笔记
在xpath获取内容元素去除括号
normalize-space
price = tree.xpath("normalize-space(//div//strong[@id='J_StrPrice']//em[@class='tb-rmb-num']/text())")
Python文件带图片打包exe
安装
pip install pywin32
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
pyinstaller -F --noupx -w -i favicon.ico main.py -n name
-F:打包成一个EXE文件
-w:不带console输出控制台,window窗体格式
–paths:依赖包路径
–icon:图标
–noupx:不用upx压缩
–clean:清理掉临时文件
sql 语句加引号
good.title = '"%s"'%(title)
日期时间
from datetime import datetime, date, timedelta
update_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) #当前时间
end_times = (date.today() + timedelta(days=-7)).strftime("%Y-%m-%d 23:00:00") # 7天前日期
json添加数据
good = {
'partnerId': 233035, 'poiId': 42367975, 'roomId': 127843856, 'goodsId': 624959748, 'roomName': '商务房B'}
good["checkInDate"] = "2020-04-17"
good['checkOutDate'] ="2020-09-18"
good['poiId'] = 123
放大桌面全屏
driver.maximize_window() # 浏览器显示最大屏幕
去除空行
strip()
获取selenium按钮后标签值
age_index = str(driver.find_element_by_xpath(".//*[@id='rd-resumelist-pageNum']").text)
a.find_element_by_css_selector('div.js-component-component>span.nui-tree-item-text').click()
判断执行时间
start = time.time()
end = time.time() - start
print(end)
合并一对多
tables = {
'name':'232','name':'wewe','val':'23232'}
dic = {
}
for n in tables:
t = ((n['value']),)
if n['name'] not in dic:
dic[n['name']] = t
else:
dic[n['name']] +=t
import datetime
import time
from time import strftime
当前日期
start_times = time.strftime('%Y%m%d',time.localtime(time.time()))