随笔分类 -  Python

python使用httpHandler处理请求案例
摘要:#coding=utf-8 #HTTPHandler & opener #更高级一些功能,可以高仿模拟浏览器 import urllib.request import urllib.parse url = "https://www.baidu.com/"; handler = urllib.requ 阅读全文

posted @ 2020-05-07 19:02 孤灯引路人 阅读(1335) 评论(0) 推荐(0) 编辑

使用python中urllib.request.Request()来构建ua
摘要:1.代码案例=构建http请求头 #coding=utf-8 import urllib.request import urllib.parse url = "http://www.baidu.com/" headers={ 'User-Agent': 'Mozilla/5.0 (Windows N 阅读全文

posted @ 2020-05-04 16:16 孤灯引路人 阅读(713) 评论(0) 推荐(0) 编辑

python中urllib.request对象案例
摘要:刚刚接触爬虫,基础的东西得时时回顾才行,这么全面的帖子无论如何也得厚着脸皮转过来啊! 什么是 Urllib 库? urllib 库 是 Python 内置的 HTTP 请求库。urllib 模块提供的上层接口,使访问 www 和 ftp 上的数据就像访问本地文件一样。 有以下几种模块: 1.urll 阅读全文

posted @ 2020-03-01 18:53 孤灯引路人 阅读(303) 评论(0) 推荐(0) 编辑

python错误捕获练习
摘要:一:错误捕获联系例子 #codeing=utf-8 def test_index(string,index): print string[index]; str="thiistest"; num=3; try:#尝试运行 test_index(str,num); except IndexError: 阅读全文

posted @ 2020-02-29 18:20 孤灯引路人 阅读(160) 评论(0) 推荐(0) 编辑

python多线程
摘要:python的线程操作在旧版本中使用的是thread模块,在Python27和Python3中引入了threading模块,同时thread模块在Python3中改名为_thread模块,threading模块相较于thread模块,对于线程的操作更加的丰富,而且threading模块本身也是相当于 阅读全文

posted @ 2020-02-29 15:03 孤灯引路人 阅读(161) 评论(0) 推荐(0) 编辑

python多进程练习
摘要:multiprocessing包是Python中的多进程管理包。与threading.Thread类似,它可以利用multiprocessing.Process对象来创建一个进程 #coding=utf-8 import time import multiprocessing import os d 阅读全文

posted @ 2020-02-29 13:51 孤灯引路人 阅读(243) 评论(0) 推荐(0) 编辑

python练习题【二】
摘要:问题:使用struct来构建tcp数据包 #coding=utf-8 from random import randint import struct #源端口 source_port = randint(1,65535); #目的端口 dst_port = 23; #32位确认序号 ack_sn= 阅读全文

posted @ 2020-02-24 23:31 孤灯引路人 阅读(208) 评论(0) 推荐(0) 编辑

python文件目录练习题【一】
摘要:问题:找到在某个目录下面所有的文件内容里面有关键字"info"的文件,将这些文件路径存储在一个t1.pkl的文件里面 #coding=utf-8 import os; import re; import pickle; #遍历改目录下所有文件的路径 root_path = "./txt"; file 阅读全文

posted @ 2020-02-24 18:35 孤灯引路人 阅读(532) 评论(0) 推荐(0) 编辑

python文件操作
摘要:python文件操作 文件操作 读取文件(开 - 读 - 关) file1 = open('/Users/Ted/Desktop/test/abc.txt',mode='r',encoding='utf-8') open()函数里面有三个参数: ①第一个参数是文件的保存地址,一定要写清楚,否则计算机 阅读全文

posted @ 2020-02-24 18:23 孤灯引路人 阅读(209) 评论(0) 推荐(0) 编辑

python正则模块re使用案例
摘要:案例1从固定字符串中进行提取 import re data ='''{'WWW-Authenticate': 'Basic realm="13FFF07B-948F-4654-8DDF-72680B6EE312"', 'Content-Length': '0', 'Date': 'Wed, 07 A 阅读全文

posted @ 2020-02-23 16:34 孤灯引路人 阅读(278) 评论(0) 推荐(0) 编辑

python字符串常用方法
摘要:python 字符串常用操作方法 python 字符串操作常用操作,如字符串的替换、删除、截取、赋值、连接、比较、查找、分割等 1、去除空格 str.strip():删除字符串两边的指定字符,括号的写入指定字符,默认为空格 a=' hello ' b=a.strip() print(b) 输出:he 阅读全文

posted @ 2020-02-22 17:35 孤灯引路人 阅读(297) 评论(0) 推荐(0) 编辑

Python学习【三】
摘要:#coding=utf-8 #import linecache; #data_keys = ('bid', 'uid', 'username', 'v_class', 'content', 'img', 'created_at', 'source', 'rt_num', 'cm_num', 'rt_ 阅读全文

posted @ 2020-01-05 21:03 孤灯引路人 阅读(131) 评论(0) 推荐(0) 编辑

Python学习【二】
摘要:案例演示2 #coding=utf-8 # dict={"name":"lisi","age":20,"sex":1,"address":"aa"}; # search_val="aa"; # search_list=[]; # for key,val in dict.items(): # if v 阅读全文

posted @ 2020-01-05 21:02 孤灯引路人 阅读(143) 评论(0) 推荐(0) 编辑

python学习【一】
摘要:python学习 #coding=utf-8 #2题 取出整数成为一个字符串 #str="sjdkf11kjsfdskl123121"; #str1=[]; #for num in str: # if num.isdigit(): # str1.append(num); #print "".join 阅读全文

posted @ 2020-01-05 21:00 孤灯引路人 阅读(152) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示