当前位置: 首页 > news >正文

西北电力建设甘肃工程公司网站足球比赛直播回放

西北电力建设甘肃工程公司网站,足球比赛直播回放,做网站做小程序推广,有谁知道哪个网址文章目录 爬虫介绍requsets模块和快速使用携带请求头携带cookie的两种方式post携带参数模拟登录 取出cookie和处理cookie响应对象证书使用代理超时 异常处理 上传文件 爬虫介绍 # 爬虫是什么#xff1f;-通过编程技术---》把互联网中的数据---》获取到---》数据清洗---》存到… 文章目录 爬虫介绍requsets模块和快速使用携带请求头携带cookie的两种方式post携带参数模拟登录 取出cookie和处理cookie响应对象证书使用代理超时 异常处理 上传文件 爬虫介绍 # 爬虫是什么-通过编程技术---》把互联网中的数据---》获取到---》数据清洗---》存到库中python:request,selenium---》app小程序网站---》xpahtlxml---》mysqlredis文件excelmongodb-通过编程语言---》模拟发送http请求---》获取数据---》解析--》入库-爬取过程 解析过程 会遇到反扒-抓app小程序---》抓包工具---》抓取手机发送的所有请求-charles-Fiddler# 爬虫 有爬虫协议-君子协议-https://xxx/robots.txt # 百度 是个大爬虫-百度/谷歌 搜索引擎---》启动了一个爬虫---》一刻不停的在互联网中爬取网站---》存到库中(es)-用户在百度输入框中---》输入搜索内容---》去百度的库中搜索--》返回给前端---》前端点击---》去了真正的地址-seo 优化-不花钱---》搜索关键词的结果---》排的靠前-伪静态-sem 优化-花钱买关键词requsets模块和快速使用 import requests# gie携带参数 # 第一种 直接写在地址栏中 res requests.get(https://api.map.baidu.com/place/v2/search?ak6E823f587c95f0148c19993539b99295region上海query肯德基outputjson) print(res.text)# 第二种 params {} params {ak: 6E823f587c95f0148c19993539b99295,region: 上海,query: 肯德基,output: json, }res requests.get(https://api.map.baidu.com/place/v2/search, paramsparams) print(res.text)# 编码与解码 from urllib.parse import quote,unquote s上海 # %E4%B8%8A%E6%B5%B7 print(quote(s))print(unquote(%E4%B8%8A%E6%B5%B7))携带请求头 import requests# 携带请求头 如果程序模拟的不像 访问不到数据 headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 } res requests.get(https://dig.chouti.com/,headersheaders)print(res.text) 携带cookie的两种方式 # 发送post请求 # 请求头的参数必带 # 携带cookie的第一种方式 headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36,# 登录之后回返回cookie 没有登录---》返回的数据不是咱们想要的Cookie: tokeneyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqaWQiOiJjdHVfNzA4NjEwMzY4NTkiLCJleHBpcmUiOiIxNzExMjAyMzY4ODAyIn0.TnUYjU6KqR1itEW6QkTSSUfqc48rkT3hnsg4Cvh4XA4; path/; Max-Age2592000, } # 你点赞作品的id号 data {linkId: 41601398 } # 在请求头中注意点赞的地址 res requests.post(https://dig.chouti.com/link/vote,headersheaders,datadata) print(res.text)# 第二种携带cookie的方式 headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36, } data {linkId: 41600539 } cookie {# 如果不成功 继续携带参数测试token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqaWQiOiJjdHVfNzA4NjEwMzY4NTkiLCJleHBpcmUiOiIxNzExMjAyMzY4ODAyIn0.TnUYjU6KqR1itEW6QkTSSUfqc48rkT3hnsg4Cvh4XA4; path/; Max-Age2592000, } # 没有登录---》返回的数据不是咱们想要的 res requests.post(https://dig.chouti.com/link/vote, headersheaders, datadata, cookiescookie) print(res.text)post携带参数 import requests # 方式一data参数:urlencoded # post请求三种编码方式jsonurlencodedform-data # 咱们以data字典形式携带---urlencoded编码---》最终它会被编码为---》namelqzage19 --放在请体中 #data{} resrequests.post(地址,datadata) # resrequests.post(地址,data{name:lqz,age:19}) resrequests.post(地址,databnamelqzage19)# 方式二json编码:json # 咱们以json字典形式携带---json编码---》最终它会被编码为---》{name:lqz,age:19} --放在请体中 resrequests.post(地址,json{name:lqz,age:19})模拟登录 取出cookie和处理cookie import requests # 第一种方式 import requestsdata {username: 616564099qq.com,password: lqz123111,captcha: 3333,remember: 1,ref: http://www.aa7a.cn/, # 你想购买产品但是没登录 登录成功重定向到这个地址act: act_login, } header {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 } # 提交数据登录 res requests.post(http://www.aa7a.cn/user.php, headersheader, datadata) print(res.text) # 登录成功的cookie cookies res.cookies print(cookies)# 向首页发送请求---登录状态 res requests.get(http://www.aa7a.cn/, cookiescookies) print(616564099qq.com in res.text)# 第二种 import requests session requests.session() # 以后发送请求使用sessiondata {username: 616564099qq.com,password: lqz12311,captcha: 3333,remember: 1,ref: http://www.aa7a.cn/, # 登录成功重定向到这个地址act: act_login, } header {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 } # session自动获取cookie并且携带过去 res session.post(http://www.aa7a.cn/user.php, headersheader, datadata)# 向首页发送请求---登录状态 res1 session.get(http://www.aa7a.cn/)# 登录成功之后可以判断一下用户之后在不在登录页面 print(616564099qq.com in res1.text)响应对象 # response 对象---》http响应### 使用requests模块 # 发送请求request对象请求头请求参数请求体---》本质就是http请求--》被包装成一个对象 # 响应回来response对象http响应--》cookie响应头响应体。。# 爬取图片--》图片防盗链---》referfer--》请求头中即可import requestsheader {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 } respone requests.get(https://www.jianshu.com/,headersheader) # respone属性 print(respone.text) # 响应体---》字符串形式print(respone.content) # 响应体---》bytes格式print(respone.status_code) # 响应状态码print(respone.headers) # 响应头 print(respone.cookies) # 响应的cookie print(respone.cookies.get_dict()) # cookiejar对象---转成字典格式 print(respone.cookies.items()) # cookie的value值print(respone.url) # 请求地址 print(respone.history) # 访问历史---》重定向才会有print(respone.encoding) # 编码格式res respone.iter_content() # 图片,视频---》迭代着把数据保存到本地 # 如果下载图片视频。。。# 图片防盗链---》通过referer做的--》请求头中有个referer参数--》上次访问的地址 # resrequests.get(https://tupian.qqw21.com/article/UploadPic/2022-2/20222102371522350.jpg)import requestsheader {Referer: http://www.baidu.com # 从哪里访问的 } res requests.get(https://meizi5.com/wp-content/uploads/2024/02/VOL_181_1.jpg, headersheader) print(res.url) print(res.content) with open(美女.jpg,wb) as f:f.write(res.content)# with open(code.jpg, wb) as f: # for line in res.iter_content(chunk_size1024): # 每次写入文件多大 防止数据量过大 # f.write(line) 证书 # http 和 https-http超文本传输协议-https安全的超文本传输协议-httpshttpssl/tls-防止篡改截取。。。。-必须有证书才能通信import requests header {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 } respone requests.get(https://www.jianshu.com/,headersheader,verifyFalse)# 加上这个就不验证证书 # respone requests.get(https://www.jianshu.com/,headersheader,cert(/path/server.crt,/path/key)) print(respone.text)使用代理 import requests # 免费代理池 很少有用的 发一个请求取出一次代理 res requests.get(http://demo.spiderpy.cn/get/?typehttps) print(res.json()) print(res.json()[proxy]) # 取出代理 # 112.30.155.83:12792header {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 } # proxies{https: res.json()[proxy]} 使用代理获取数据 如果代理用不了 则是连接失败 response requests.get(https://www.jianshu.com/, headersheader, proxies{https: res.json()[proxy]}) print(response.text)超时 异常处理 上传文件 ## 超时 自己设置一个时间 超过时间数据没请求会来就报错 import requests responerequests.get(https://www.baidu.com,timeout1)# 异常处理 import requests from requests.exceptions import * #可以查看requests.exceptions获取异常类型try:rrequests.get(http://www.baidu.com,timeout0.00001) except ReadTimeout:print(:) # except ConnectionError: #网络不通 # print(-----) # except Timeout: # print(aaaaa)except RequestException:print(Error)# 上传文件import requests files{file:open(a.jpg,rb)} responerequests.post(http://httpbin.org/post,filesfiles) print(respone.status_code)
http://www.zqtcl.cn/news/259083/

相关文章:

  • 南宁网站建设培训学校青海网站建设加q5299丶14602做词
  • 鱼台做网站多少钱wordpress pot
  • 招聘网站建设维护人员怎样自己开发一款软件
  • 上海网站制作怎么选泰安网红人物
  • 企业网站建设义乌南靖网站建设
  • 抖音电商网站建设如何制作app推广
  • 关键词的选择网站提示网站建设电销异议处理话术
  • 南京建设网站内容网站打开速度慢是否需要升级带宽
  • 内容类网站如何 流量厦门市建设局网站住房保障专栏
  • 朝城做网站公司网站内容建设要求age06
  • 云南省城乡建设培训中心网站备份wordpress网站
  • 快速建站公司地址vr哪家公司做得好
  • 网站空间怎么更换网站营销如何做
  • 制作单页网站要网址wordpress更新显示失败
  • 阿里巴巴网站建设公司设计网站制作
  • 泰安网站建设有哪些常见的cms网站程序有哪些
  • 九寨沟城乡建设官方网站深圳的互联网公司排名
  • app可视化开发工具seo网站推广服务
  • 临近做网站网络营销方式哪些?
  • 网站数据分析案例怎样在网上做广告
  • 网站页头图片怎么做几个版面的网站
  • 网站 f型网站建设 大公司
  • 做网站最好选什么语言百度域名服务器
  • 网站维护一般多久西宁的网站建设
  • 网站建设需要什么工具投诉百度最有效的电话
  • 做家政网站公司策划公司英文
  • 自己建设个人网站要花费多少自己怎么制作微信网页链接
  • 邢台网站设计哪家专业php图书管理系统网站开发
  • 怎么去建一个网站艺术设计专业
  • 中国优秀设计网站有哪些内容万能影视免费观看app