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

wordpress导航站主题免费建站资源

wordpress导航站主题,免费建站资源,好模版网站,企业营销策划咨询爬虫介绍 # 爬虫的概念#xff1a; 通过编程技术(python:request,selenium)#xff0c;获取互联网中的数据(app#xff0c;小程序#xff0c;网站)#xff0c;数据清洗(xpaht#xff0c;lxml)后存到库中(mysql#xff0c;redis#xff0c;文件#xff0c;excel#x…爬虫介绍 # 爬虫的概念         通过编程技术(python:request,selenium)获取互联网中的数据(app小程序网站)数据清洗(xpahtlxml)后存到库中(mysqlredis文件excelmongodb) # 基本思路         通过编程语言模拟发送http请求获取数据解析入库# 过程         爬取过程解析过程会遇到反扒         抓app小程序会通过抓包工具(charlesFiddler)抓取手机发送的所有请求# 爬虫协议         君子协议https://xxx/robots.txt# 百度是个大爬虫     百度/谷歌搜索引擎启动了一个爬虫一刻不停的在互联网中爬取网站存到库中(es)     用户在百度输入框中输入搜索内容去百度的库中搜索返回给前端前端点击去了真正的地址     seo 优化不花钱搜索关键词的结果排的靠前         -伪静态     sem 优化花钱买关键词 requests模块介绍 # requests模块模拟发送http请求模块封装了urlib3(python内置的发送http请求的模块)     爬虫会用     后端: 向其他api接口发送请求     同步 #  requests库发送请求将网页内容下载下来以后并不会执行js代码这需要我们自己分析目标站点然后发起新的request请求 # 第三方 pip3 install requests requests发送get请求 #  requests可以模拟发送http请求有的时候网站会禁止         禁止的原因是模拟的不像有的东西没带 # http请求:请求头中没带东西没带cookie客户端类型referer... import requests resrequests.get(https://www.cnblogs.com/) # 这个网站没有反扒 print(res.text) # 响应体内容 携带get参数 # 携带get参数方式一 import requests resrequests.get(https://api.map.baidu.com/place/v2/search?ak6E823f587c95f0148c19993539b99295region上海query肯德基outputjson) print(res.text) # 携带get参数方式二 import requests params {ak: 6E823f587c95f0148c19993539b99295,region: 上海,query: 肯德基,output: json, } res requests.get(https://api.map.baidu.com/place/v2/search,paramsparams) print(res.text)  # 响应体内容 # url 编码和解码 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) 发送post请求携带cookie # 是否登录有个标志         前后端混合项目登录信息--放在cookie中了         前后端分离项目登录信息--》后端规定的--》放在请求头的 # 方式一放在请求头中 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,Cookie: deviceIdweb.eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqaWQiOiJiNjEzOGM2OS02ZWRlLTQ3MWItODI4Yy03YTg2ZTE3M2E3NjEiLCJleHBpcmUiOiIxNzEwOTAxNjM1MTMxIn0.JluPFMn3LLUGKeTFPyw7rVwR-BWLiG9V6Ss0RGDHjxw; Hm_lvt_03b2668f8e8699e91d479d62bc7630f11708309636; __snaker__idmiaeDoa9MzunPIo0; gdxidpyhxdElMhl43kDvnAOqQQcQs9vEoTiy8k90nSwfT3DkVSzGwu3uAQWI9jqa2GcIUvryeOY0kX6kfPuhJUAGrR6ql0iv%2F6mCzqh6DHE1%5CP%2BaIXeUQgLcfqlklCcq2V9CgWbvQRGeRaduwzkcPYwf6CXZiW9a87NxU%2BRlYq57Zq01j2gMK0BaX%2FK%3A1708310847499; tokeneyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqaWQiOiJjZHVfNTMyMDcwNzg0NjAiLCJleHBpcmUiOiIxNzEwOTAxOTY5NTM2In0.eseWTCMqp-yHa7rWgSvPhnWVhhQAgqGIvIgLGbvcBcc; Hm_lpvt_03b2668f8e8699e91d479d62bc7630f11708309982 } data {linkId: 41566118 # 文章id } # 没有登录---》返回的数据不是咱们想要的 res requests.post(https://dig.chouti.com/link/vote, headersheaders, datadata) print(res.text) # 方式二放在cookie中         cookie特殊后期用的频率很高 import requestsheaders {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: 41566118 } cookie {token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqaWQiOiJjZHVfNTMyMDcwNzg0NjAiLCJleHBpcmUiOiIxNzEwOTAxOTY5NTM2In0.eseWTCMqp-yHa7rWgSvPhnWVhhQAgqGIvIgLGbvcBcc }# 没有登录---》返回的数据不是咱们想要的 res requests.post(https://dig.chouti.com/link/vote, headersheaders, datadata, cookiescookie) print(res.text) post请求携带参数 # post请求有三种编码方式                 jsonurlencodedform-data # 方式一data参数是urlencoded         以data字典形式携带urlencoded编码最终会被编码为namelqzage19放在请体中 import requests resrequests.post(地址,data{name:lqz,age:19}) # resrequests.post(地址,databnamelqzage19) # 方式二json编码:json         # 以json字典形式携带json编码最终它会被编码为{name:lqz,age:19}放在请体中 import requests resrequests.post(地址,json{name:lqz,age:19}) 模拟登录 # 登录接口通过post请求登录后能拿到登录信息再发请求携带登录信息就是登录状态         可见即可爬 import requestsdata {username: 616564099qq.com,password: lqz123,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 cookiesres.cookies print(cookies)# 向首页发送请求---携带cookie便是登录状态 resrequests.get(http://www.aa7a.cn/,cookiescookies) print(616564099qq.com in res.text) 响应对象 # 使用requests模块发送请求:  request对象请求头请求参数请求体         本质就是http请求,被包装成一个对象 # 响应回来response对象有http响应cookie响应头响应体...         requesthttp请求         responsehttp响应     # 爬取普通图片 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) #  如果下载图片视频         图片防盗链通过referer做的请求头中有个referer参数上次访问的地址 import requests header{Referer:https://www.tupianzj.com/ } resrequests.get(https://img.lianzhixiu.com/uploads/allimg/180514/9-1P514153131.jpg,headersheader) 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) # 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)  # 编码格式response.iter_content() # 图片,视频---》迭代着把数据保存到本地 ssl 认证 # http和 https:     http超文本传输协议     https安全的超文本传输协议防止被篡改截取...     httpshttpssl/tls     必须有证书才能通信 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,verifyFalse) # respone requests.get(https://www.jianshu.com/,headersheader,cert(/path/server.crt,/path/key)) print(respone.text) 使用代理 # 代理有正向代理和向代理 # 大神写了开源的免费代理         原理有些网站提供免费的代理通过爬虫技术爬取别人的免费代理验证过后自己用                加入自己的id访问不了可以使用免费代理生成id再去访问 import requestsres requests.get(http://demo.spiderpy.cn/get/?typehttps) print(res.json()) print(res.json()[proxy])# 112.30.155.83:12792 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, proxies{https: res.json()[proxy]}) respone requests.get(https://www.jianshu.com/, headersheader) print(respone.text) 超时设置异常处理上传文件 # 超时: import requests responerequests.get(https://www.baidu.com,timeout0.0001) print(respose.text) # 异常处理: import requests from requests.exceptions import * #可以查看requests.exceptions获取异常类型 try:rrequests.get(http://www.baidu.com,timeout0.00001) except RequestException:print(Error) # except ConnectionError: #网络不通 #     print(-----) # except Timeout: #     print(aaaaa) # 上传文件: import requests files{file:open(a.jpg,rb)} responerequests.post(http://httpbin.org/post,filesfiles) print(respone.status_code) 今日思维导图
http://www.dnsts.com.cn/news/63475.html

相关文章:

  • 建网站 找个人2017网站开发语言排名
  • 重庆建站费用访客留言网站
  • 做门户类网站报价龙溪网站制作
  • 最专业网站建设哪家好温州网站建设定制
  • 公司网站管理管理咨询培训
  • 做设计开哪个素材网站的会员好wordpress搬家500
  • 泰州模板自助建站京网站建设公司
  • 网站建设服务上海12380网站建设情况总结
  • 如何做免费的公司网站新网站关键词怎么优化
  • 苍南县网站集约化建设2018年做网站赚钱吗
  • 网站建设廉政风险点网站开发怎么根据设计稿的尺寸算图片高度
  • 网站管理的主要内容app制作手机版
  • 网站的主题有哪些三合一网站建设平台
  • 天台县低价网站建设浙江省建设厅建筑信息网官网
  • 如何做网站相册html网页制作代码大全
  • 邯郸移动网站建设企业内部网站源码
  • 设计专业网站有哪些三亚制作网站
  • 撤销网站备案表填写后斗牛app开发公司
  • 长春火车站官网wordpress 营销模板下载
  • win 2012 iis 默认网站百度h5游戏中心
  • 长沙建网站小程序软件制作网站
  • 广告网站建设网软件开发做网站
  • 台州网站制作方案线上商城是什么软件
  • 网站建设大概多少费用wordpress手机上发文章
  • 北京电商网站建设哪家好河南郑州消费情况
  • 厦门网站建设建网站济南做网站的哪家好
  • 做网站 报价51CTO学院个人网站开发视频
  • wordpress减肥网站采集规则百度站长工具app
  • 低价代网站如何进行课程中心网站建设
  • 建设公司网站开发方案线上线下一体化营销