会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
自己的阿毛
博客园
首页
新随笔
联系
订阅
管理
2021年6月23日
requests 对 RequestscookieJar 和 字典 相互转换
摘要: import requests url = 'https://movie.douban.com/' r = requests.get(url) # r.cookies 是RequestsCookieJar对象 print(r.cookies) mycookies = r.cookies # Requ
阅读全文
posted @ 2021-06-23 13:02 自己的阿毛
阅读(614)
评论(0)
推荐(0)
2021年6月22日
编码处理
摘要: import urllib.request import urllib.parse bianma = '编程' one = urllib.parse.quote(bianma) print(one) two = urllib.parse.quote(one) print(two) three = u
阅读全文
posted @ 2021-06-22 21:43 自己的阿毛
阅读(26)
评论(0)
推荐(0)
数据处理
摘要: import urllib.request import urllib.parse headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
阅读全文
posted @ 2021-06-22 21:34 自己的阿毛
阅读(36)
评论(0)
推荐(0)
关闭证书验证
摘要: import urllib.request import ssl # 关闭ssl证书验证(固定写法) ssl._create_default_https_context = ssl._create_unverified_context url = 'https://inv-veri.chinatax
阅读全文
posted @ 2021-06-22 21:18 自己的阿毛
阅读(388)
评论(0)
推荐(0)
读取cookie
摘要: import urllib.request from http import cookiejar filename = 'cookie.txt' # 创建MoillaCookiejar对象 cookie = cookiejar.MozillaCookieJar() # 读取cookie变量 cook
阅读全文
posted @ 2021-06-22 21:08 自己的阿毛
阅读(78)
评论(0)
推荐(0)
保存cookie
摘要: 目前还没看懂,mozillacookiejar 啥子意思 网上都是基本上是复制粘贴的,没讲明白。 所以就死记硬背吧。 记住民工三连: cookie = cookiejar.Mozillacookiejar(filename) handler = urllib.request.HTTPCookiePr
阅读全文
posted @ 2021-06-22 20:50 自己的阿毛
阅读(98)
评论(0)
推荐(0)
2021年6月21日
使用代理ip读取html
摘要: urllib.request.ProxyHandler() 可以动态设置代理IP池 urllib.request.build_opener() 将代理IP池中的ip写入该方法生成opener opener.open(url) 打开url 代码如下: # 导入urllib import urllib.
阅读全文
posted @ 2021-06-21 23:38 自己的阿毛
阅读(166)
评论(0)
推荐(0)
Urllib.requset.Request加入请求头部
摘要: 上一个随笔中报错: urllib.error.HTTPError: HTTP Error 418: 百度后,加上头部得以解决。 urllib.request.Request 功能:声明一个request对象。可自定义header等请求信息。 本次,加入一个更多参数的header。 # 导入urlli
阅读全文
posted @ 2021-06-21 23:22 自己的阿毛
阅读(354)
评论(0)
推荐(0)
Urllib.request 抓取网页html
摘要: 语法 urllib.request.urlopen 意思就是打开 url # 导入urllib import urllib.request # 打开url response = urllib.request.urlopen('https://movie.douban.com/', None, 10)
阅读全文
posted @ 2021-06-21 23:09 自己的阿毛
阅读(522)
评论(0)
推荐(0)
2020年12月15日
利用装饰器装饰login_required ,实现判断User表中的是否是管理员的判断
摘要: 在写图书管理系统的时候遇到需要将管理员页面和普通用户页面分离。普通用户无法访问管理员页面。于是想用装饰器。 def check_login(func): @login_required(login_url='/account/login/') #装饰器嵌套 def wrapper(request,*
阅读全文
posted @ 2020-12-15 22:16 自己的阿毛
阅读(126)
评论(0)
推荐(0)
下一页
公告