win10安装python3绿色版和pip3

0x01 下载解压包 https://www.python.org/downloads/windows/ 0x02 解压到任意目录 0x03 配置环境变量 <python安装目录> <python安装目录>/Scripts 0x04 下载pip安装脚本 https://bootstrap.pypa.io/get-pip.py 0x05 安装pip 打开cmd,输入python <下载目录>/get-pip.py 打开<python安装目录>修改python39._pth文件,去掉#import site前#号 0x06 验证 打开cmd,输入一下命令验证是否成功 python -V pip -V

2020-12-13

python字符串转json

字符串转json import json s='{"url": "https://img.bovod.org/blog/typecho/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5.jpg"}' j=json.loads(s) print(j['url']) json转字符串 import json j = {"url":"https://img.bovod.org/blog/typecho/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5.jpg"} s=json.dumps(j) print(s) 字符串转json时字符串必须严格的json格式,属性名和字符串必须用双引号,单引号的话会报错,单引号的json串可以用ast包的literal_eval转 import ast s="{'url': 'https://img.bovod.org/blog/typecho/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5.jpg'}" j = ast.literal_eval(s) print(j['url'])

2019-12-11

python 无头浏览器

安装selenium pip install selenium 安装chromedriver 查看本地chrome浏览器版本,安装对应的chromedriver chromedriver下载地址 示例代码 # -*- coding: utf-8 -*- import os from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options import time chrome_options = Options() chrome_options.add_argument("--headless") base_url ="http://www.baidu.com/" #对应的chromedriver的放置目录 driver = webdriver.Chrome(executable_path=(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'), chrome_options=chrome_options) driver.get(base_url +"/") start_time=time.time() print('this is start_time ',start_time) driver.find_element_by_id("kw").send_keys("selenium webdriver") driver.find_element_by_id("su").click() driver.save_screenshot('screen.png') driver.close() end_time=time.time() print('this is end_time ',end_time)

2019-12-01