05 2019 档案
摘要:https://developers.google.com/web/tools/chrome devtools/?hl=zh cn
阅读全文
摘要:解析库 |解析器|使用方法|优势|劣势| | | | | | | Python标准库 | BeautifulSoup(markup, "html.parser") | Python的内置标准库、执行速度适中 、文档容错能力强 | Python 2.7.3 or 3.2.2)前的版本中文容错能力差|
阅读全文
摘要:首先安装相关的库 然后使用该库 最好的,通过真实世界的浏览器使用统计随机 除了使用fake useragent,Faker也可以实现相同操作 首先安装faker 例如: 效果如下: 参考原文:http://www.chenxm.cc/post/534.html
阅读全文
摘要:```
import os path="E:\\python" #批量的py文件路径 for root,dirs,files in os.walk(path): #进入文件夹目录 for f in files: #文件夹下的文件 if os.path.splitext(f)[1]=='.py': #只运行py文件 os.chdir(root)
...
阅读全文
摘要:1、字体、字号、颜色设置 上述设置显示效果如下所示: 微软雅黑字体 黑体 3号字 4号字 红色 绿色 蓝色 注意: CSDN中的blog默认字号为3号字,字号数值可设为1~7,默认字体为微软雅黑。其它颜色值可参考 "CSDN markdown编辑器语法——字体、字号与颜色" 字体、字号以及颜色可在中
阅读全文
摘要:python所有包、模块镜像站 https://www.lfd.uci.edu/~gohlke/pythonlibs/
阅读全文
摘要:要求: 把.md格式转为.pdf格式,并批量处理,最后将多个pdf文件合并为一个pdf并以文件名作为书签名 解决思路: 1.md格式的markdown文件转为html 为了将 md 格式转换成 html 文件,我们需要用到 markdown 和 codecs 这两个库。 完整代码如下: import
阅读全文
摘要:本节内容 Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko SSH Twsited网络框架 引子 到目前为止,我们已经学了网络并发编程的2个套路, 多进程,多线程,
阅读全文
摘要:实现过程: 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关。 转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示是27,用八进制表示就是033)。 书写格式: 开头部分:\033[显示方式;前景色;背景色m + 结尾部分:\033[0m 注意
阅读全文
摘要:有时候导入本地模块或者py文件时,下方会出现红色的波浪线,但不影响程序的正常运行,但是在查看源函数文件时,会出现问题 问题如下: 解决方案: 1. 进入设置,找到Console下的Python Console,勾选选项“Add source roots to PYTHONPAT” 2. 在当前项目程
阅读全文
摘要:#字典 #字典是Python中唯一内建的映射类型。字典中没有特殊的顺序,但都是存储在一个特定的键(key)下面,键可以是数字,字符串,甚至是元组 #一、字典的使用 #在某些情况下,字典比列表更加适用: #1、表示一个游戏棋盘的状态,每个键都是由坐标值组成的元组 #2、存储文件修改时间,用文件名作为键; #3、数字电话\地址薄 #1、使用列表创建一个电话本,(这里用字符串表示电话号码,以0开头...
阅读全文
摘要:# -*- coding: utf-8 -*- import numpy as np import pandas as pd #一、创建数据 #1.通过传递一个list对象来创建一个Series,pandas会默认创建整型索引 s = pd.Series([1,3,np.nan,5,8]) #2.通过传递一个numpy array,时间索引以及列标签来创建一个DataFrame dates ...
阅读全文
摘要:本节内容 操作系统发展史介绍 进程、与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线程变为守护进程 Event事件 queue队列 生产者消费者模型 Queue队列 开发一个线程池 进程 语法 进程间通讯 进程池 操作系统发展史 手工操作
阅读全文
摘要:本节内容: 面向对象高级语法部分 经典类vs新式类 静态方法、类方法、属性方法 类的特殊方法 反射 异常处理 Socket开发基础 作业:开发一个支持多用户在线的FTP程序 面向对象高级语法部分 经典类vs新式类 把下面代码用python2 和python3都执行一下 #_*_coding:utf-
阅读全文
摘要:1. 所有参数包括appkey或者token拼接成&key=value格式 2. 转小写 3. 正序排序 4. MD5后得到sign
阅读全文
摘要:```
with open('filename','r') as csv_f: reader = csv.reader(csv_f) fieldnames = next(reader) csv_reader = csv.DictReader(f,fieldnames=fieldnames) for row in csv_reader: d = {}
...
阅读全文
摘要:读取CSV(逗号分割)文件到DataFrame 也支持文件的部分导入和选择迭代 更多帮助参见:http://pandas.pydata.org/pandas docs/stable/io.html 参数: filepath_or_buffer: str,pathlib。str, pathlib.Pa
阅读全文
摘要:在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在脚本中直接使用其他脚本或程序提供的功能,而不必再次编写实现该功能的代码。为了更好地控制运行的进程,可以使用win32process模块中的函数,如果想进一步控制进程,则可以使用ctype模块,直接调用kernel32.dll
阅读全文
摘要:因为json数据不规范出现了以下问题: 网上查到可以使用demjson来处理 安装 demjson的介绍 快速说明: http://deron.meranda.us/python/demjson/ demjson有两个主要的方法: encode 编码,将对象转换为json decode 解码,将js
阅读全文
摘要:方法1:采用sys.exit(0)正常终止程序,从图中可以看到,程序终止后shell运行不受影响。 方法2:采用os._exit(0)关闭整个shell,从图中看到,调用sys._exit(0)后整个shell都重启了(RESTART Shell)。 方法3:采用Ctrl+C快捷键,强制终止程序执行
阅读全文
摘要:``` 用asyncio和aiohttp抓取博客的总阅读量 (提示:先用接又找到每篇文章的链接) https://www.jianshu.com/u/130f76596b02 import re import asyncio import aiohttp import requests import
阅读全文
摘要:``` coding:utf 8 import re import ssl import csv import json import time import random import asyncio import aiohttp import requests from lxml import
阅读全文
摘要:``` coding:utf 8 import asyncio 通过create_task()方法 async def a(t): print(' ', t) await asyncio.sleep(0.5) print('
阅读全文
摘要:``` coding:utf 8 通过gather方法 import asyncio async def a(t): print(' ', t) await asyncio.sleep(0.5) print('
阅读全文
摘要:```
import aiohttp
import asyncio
import ssl async def fetch(session, url): async with session.get(url,ssl=ssl.SSLContext()) as response: return await response.text() async def main(): ...
阅读全文
摘要:```
# 多线程
import threading
import time class myThread(threading.Thread): def __init__(self, threadID, name, counter): threading.Thread.__init__(self) self.threadID = threadID ...
阅读全文
摘要:```
# 多进程,使用Process对象
from multiprocessing import Process def f(name): print('hello', name) if __name__ == '__main__': p_1 = Process(target=f, args=('bob',)) p_1.start() p_1.join() ...
阅读全文
摘要:```
# 多进程,使用Pool
from multiprocessing import Pool def f(x): return x*x if __name__ == '__main__': p = Pool(5) list = [1,2,3,4,5,6,7,8,9] print(p.map(f, list))
``` ```
# 多进程,使用Pool
i...
阅读全文
摘要:``` # 模拟登录微博 import time import base64 import rsa import binascii import requests import re import random try: from PIL import Image except BaseException: pass try: from urllib.parse impo...
阅读全文
摘要:```
# 模拟登录豆瓣 from urllib.request import urlretrieve
import requests
from bs4 import BeautifulSoup
from os import remove
try: import cookielib
except BaseException: import http.cookiejar as co...
阅读全文
摘要:```
# 使用自造的cookies登录GitHub import requests
from lxml import etree str = '_octo=GH1.1.518803230.1537264616; logged_in=no; _ga=GA1.2.102113046.1537264618; _gh_sess=RTIralVlQ1pHaG0vVG44b3NsV0s4Z2VZTTVi...
阅读全文
摘要:```
# 使用自造的cookies登录马蜂窝
import requests
from lxml import etree str = 'mfw_uuid=5bcfcc20-b235-fbbe-c1d6-ae01e1f68d82; _r=baidu; _rp=a%3A2%3A%7Bs%3A1%3A%22p%22%3Bs%3A19%3A%22www.baidu.com%2Fbaidu%22%3B...
阅读全文
摘要:```
# 利用cookies登录马蜂窝 import requests
from lxml import etree session = requests.Session()
phone_number = '13521093039'
password = 'pro123,./'
data = {'passport': phone_number, 'password': password}
h...
阅读全文
摘要:```
# 模拟登录GitHub
import requests
from lxml import etree class Login(): def __init__(self): self.headers = { 'Referer': 'https://github.com/', 'User-Agent': 'Mozill...
阅读全文
摘要:```
# 模拟登录马蜂窝
import requests
from lxml import etree session = requests.Session()
phone_number = input('电话')
password = input('密码')
data = {'passport': phone_number, 'password': password}
header = {
...
阅读全文
摘要:什么是模拟登录? 要抓取的信息,只有在登录之后才能查看。这种情况下,就需要爬虫做模拟登录,绕过登录页。 cookies和session的区别: cookie数据存放在客户的浏览器上,session数据放在服务器上; cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗,
阅读全文
摘要:1_info.py 2_pie_chart.py 3_hist.py 4_ratio.py
阅读全文
摘要:ershoufang.py zufang_spider.py items.py middlewares.py pipelines.py settings.py
阅读全文
摘要:``` import redis import telnetlib import urllib.request from bs4 import BeautifulSoup r = redis.Redis(host='127.0.0.1', port=6379) for d in range(1, 3
阅读全文
摘要:taobao.py items.py middlewares.py pipelines.py settings.py
阅读全文
摘要:```
# python执行lua脚本 import requests
from urllib.parse import quote lua = '''
function main(splash) return 'hello'
end
''' url = 'http://localhost:8050/execute?lua_source=' + quote(lua)
response...
阅读全文
摘要:```
# 抓取《我不是药神》的豆瓣评论 import csv
import time
import requests
from lxml import etree fw = open('douban_comments.csv', 'w')
writer = csv.writer(fw)
writer.writerow(['comment_time','comment_content']) ...
阅读全文
摘要:```
# 抓取今日头条,对比渲染和没有渲染的效果 import requests
from lxml import etree # url = 'http://localhost:8050/render.html?url=https://www.toutiao.com&timeout=30&wait=0.5'
url = 'https://www.toutiao.com' response...
阅读全文
摘要:``` import requests import json import re from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.sup...
阅读全文
摘要:```
# 抓取简书博客总阅读量
# https://www.jianshu.com/u/130f76596b02
import requests
import json
import re
from lxml import etree header = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,...
阅读全文
摘要:```
# 通过搜索接口抓取etherscan上的合约地址
# https://etherscan.io/ import requests
import re header = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent...
阅读全文
摘要:```
# 抓取华尔街见闻实时快讯
# https://wallstreetcn.com/live/global?from=navbar
import requests
import json header = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',...
阅读全文
摘要:```
# 抓取36氪快讯
# https://36kr.com/newsflashes import requests
import json header = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agen...
阅读全文
摘要:``` dict_data = { "_id":1, name:"王五", age:55, gender:true } db.stu.insert(dict_data) db.stu.insert({_id:1,name:"李四",age:38,gender:true,like:"🐶🐶"}) d
阅读全文
摘要:```
import requests
from bs4 import BeautifulSoup url = 'http://wz.sun0769.com/index.php/question/reply?page=0'
headers = { 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWeb...
阅读全文
摘要:```
# 安装 pymongo pip install pymongo import pymongo try: # 1.链接mongod的服务 mongo_py = pymongo.MongoClient() # 2.库和表的名字; 有数据会自动建库建表 # 数据库 # db = mongo_py['six'] # 表 集合 # co...
阅读全文