成都创新互联网站制作重庆分公司

python如何抓取需要扫微信登陆页面-创新互联

小编给大家分享一下python如何抓取需要扫微信登陆页面,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

在阿巴嘎等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站制作、网站建设、外贸网站建设 网站设计制作按需求定制网站,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销,外贸网站建设,阿巴嘎网站建设费用合理。 一,抓取情况描述

1.抓取的页面需要登陆,以公司网页为例,登陆网址https://app-ticketsys.hezongyun.com/index.php ,(该网页登陆方式微信扫码登陆)

2.需要抓取的内容如下图所示:

需要提取

工单对应编号,如TK-2960

工单发起时间,如2018-08-17 11:12:13

工单标题内容,如设备故障

工单正文内容,如最红框所示

python如何抓取需要扫微信登陆页面

二,网页分析

1.按按Ctrl + Shift + I或者鼠标右键点击检查进入开发人员工具。

可以看到页面显示如下:

python如何抓取需要扫微信登陆页面

主要关注点如上图框住和划线处

首先点击网络,记住以下信息将用于代码修改处。

Resquest URL:https: //app-ticketsys.hezongyun.com/index.php/ticket/ticket_list/init这个是需要爬取页面的信息请求Menthod:GET饼干:用于需要登陆页面User-Agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,类似Gecko)Chrome / 67.0.3396.62 Safari / 537.36

记住以上信息后粗略了解网页树形结构用BeatifulSoup中SELEC怎么取出内容

示例:的H1M1一段代码如下:

html =“”“
  睡鼠的故事</ title> </ head>
<body>
<p class =”title“name =”dromouse“> <b>睡鼠的故事</ b > </ p>
<p class =“story”>从前有三个小姐妹;他们的名字是
<a href =“http://example.com/elsie”class =“sister”id =“ link1“> <! - Elsie - > </a>,
<a href="http://example.com/lacie" rel="external nofollow" class="sister" id="link2"> Lacie </a>和
<a href =“http://example.com/tillie”class =“sister”id =“link3”> Tillie </a>;
他们住在井底。</ p>
<p class =“story”> ... </ p>
“”“</pre><p>如果我们喝汤得到了上面那段HTML的结构提取内容方法如下</p><p>1.通过标签名查找soup.select( '标题'),如需要取出含有一个标签的内容则soup.select( 'a')的</p><p>2.通过类名查找soup.select( 'CLASS_NAME ')如取出标题的内容则soup.select('。标题')</p><p>3.通过ID名字查找soup.select( '#ID_NAME')如取出ID = LINK2的内容则soup.select( '#LINK2')</p><p>上述元素名字可以利用左上角箭头取出,如下图</p><p><img src="/upload/otherpic18/35995.jpg" alt="python如何抓取需要扫微信登陆页面"></p><strong>三,程序编写</strong><pre># -*- coding:utf-8 -*-
import requests
import sys
import io
from bs4 import BeautifulSoup
import sys
import xlwt
import urllib,urllib2
import re
def get_text():
  #登录后才能访问的网页,这个就是我们在network里查看到的Request URL
  url = 'https://app-ticketsys.hezongyun.com/index.php/ticket/ticket_iframe/'
  #浏览器登录后得到的cookie,这个就是我们在network里查看到的Coockie
  cookie_str = r'ci_ticketsys_session=‘***********************************'
  #把cookie字符串处理成字典
  cookies = {}
  for line in cookie_str.split(';'):
    key, value = line.split('=', 1)
    cookies[key] = value
  #设置请求头
  headers = {'User-Agent':'Mozilla/5.0(Windows NT 10.0; Win64;x64)AppleWebKit/537.36 (KHTML, like Gecko)Chrome/67.0.3396.62 Safari/537.36'}
  #在发送get请求时带上请求头和cookies
  resp = requests.get(url, cookies = cookies,headers = headers)
  soup = BeautifulSoup(resp.text,"html.parser")
  print soup</pre><p>上述代码就能得到登陆网页的HTML源码,这个源码呈一个树形结构,接下来针对需求我们提取需要的内容进行提取</p><p>我们需要工单号,对应时间,对应标题</p><p><img src="/upload/otherpic18/35996.jpg" alt="python如何抓取需要扫微信登陆页面"></p><p>按箭头点击到对应工单大块,可以查询到,所有的工单号,工单发起时间,工单标题均在<code><ul id =“ticket-list”></code>这个id下面</p><p><img src="/upload/otherpic18/35997.jpg" alt="python如何抓取需要扫微信登陆页面"></p><p>那么点开一个工单结构,例如工单号ID = “4427” 下面我们需要知道工单号,工单发起时间,工单内容可以看到</p><p>1.工单内容在H3标签下面</p><p>2.工单编号在类=“NUM”下面</p><p>3.工单发起时间在类= “时间” 下面</p><pre>for soups in soup.select('#ticket-list'):
  if len(soups.select('h4'))>0:
    id_num = soups.select('.num')
    star_time = soups.select('.time')
    h4 = soups.select('h4')
    print id_num,start_time,h4</pre><p>以上是“python如何抓取需要扫微信登陆页面”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!</p>            <br>
            当前标题:python如何抓取需要扫微信登陆页面-创新互联            <br>
            路径分享:<a href="http://cxhlcq.com/article/dhcoso.html">http://cxhlcq.com/article/dhcoso.html</a>
        </div>
    </div>
</div>
<div class="other container">
    <h3>其他资讯</h3>
    <ul>
        <li>
                <a href="/article/iigsij.html">win10电脑玩游戏闪退如何解决</a>
            </li><li>
                <a href="/article/iigsip.html">可以编写javascript代码的软件有哪些</a>
            </li><li>
                <a href="/article/iigshh.html">怎么在python中使用add函数</a>
            </li><li>
                <a href="/article/iigedc.html">怎么在android中通过led实现一个手电筒功能</a>
            </li><li>
                <a href="/article/iigsge.html">vue之组件在脚手架构造篇</a>
            </li>    </ul>
</div>
<div class="footer">
    <div class="foota container">
        <div class="foot_nav fl col-lg-8 col-md-8 col-sm-12 col-xs-12">
            <ul>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站制作</h3>
                    <a href="https://www.cdxwcx.com/wangzhan/mbqiye.html" target="_blank">成都企业网站制作</a><a href="http://chengdu.kswjz.com/" target="_blank">成都网站制作</a><a href="http://www.kswsj.com/" target="_blank">成都网站制作</a><a href="https://www.cdcxhl.com/zhizuo/chengdu.html" target="_blank">四川成都网站制作</a><a href="http://www.cdxtjz.com/" target="_blank">网站制作</a><a href="http://www.wjwzjz.com/" target="_blank">温江网站制作</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>企业服务</h3>
                    <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站快速收录</a><a href="https://www.cdcxhl.com/weihu/chengdu.html" target="_blank">成都网站维护</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文发布</a><a href="https://www.cdcxhl.com/service/400.html" target="_blank">400电话</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">分类目录网站</a><a href="https://www.cdcxhl.com/mianfei/jianzhan/" target="_blank">免费建站</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站建设</h3>
                    <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设公司</a><a href="https://www.cdxwcx.com/city/dujiangyan/" target="_blank">都江堰网站建设</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">成都响应式网站建设公司</a><a href="https://www.cdxwcx.com/city/guangan/" target="_blank">广安网站建设</a><a href="http://www.cxhljz.cn/" target="_blank">成都网站建设公司</a><a href="http://www.cdkjz.cn/fangan/yiyao/" target="_blank">医药医疗网站建设方案</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>服务器托管</h3>
                    <a href="https://www.xwcx.net/tgxq/cdghjf.html" target="_blank">成都光华机房</a><a href="https://www.cdcxhl.com/idc/cqyd.html" target="_blank">重庆移动机房托管</a><a href="https://www.cdxwcx.com/jifang/guanghua.html" target="_blank">光华服务器托管</a><a href="https://www.cdcxhl.com/cqtuoguan.html" target="_blank">重庆服务器托管</a><a href="https://www.cdcxhl.com/tuoguan.html" target="_blank">成都服务器托管</a><a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">成都西云机房</a>                </li>
            </ul>
        </div>
        <div class="footar fl col-lg-4 col-md-4 col-sm-12 col-xs-12">
            <p>全国免费咨询:</p>
            <b>400-028-6601</b>
            <p>业务咨询:028-86922220 / 13518219792</p>
            <p>节假值班:18980820575 / 13518219792</p>
            <p>联系地址:成都市太升南路288号锦天国际A幢1002号</p>
        </div>
    </div>
    <div class="footb">
        <div class="copy container">
            <div class="fl">Copyright © 成都创新互联科技有限公司重庆分公司  <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备2021005571号</a></div>
            <!--<div class="fr"><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:<a href="https://www.cdcxhl.com/" target="_blank">创新互联</a></div>-->
        </div>
    </div>
    <div class="link">
        <div class="container">
            友情链接::
            <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a>
            <a href="https://www.cdcxhl.com/city/chongqing.html" target="_blank">重庆网站建设</a>
            <a href="">四川网站建设</a>
            <a href="">重庆建设网站</a>
            <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">移动服务器托管</a>
            <a href="http://www.cdfuwuqi.com/" target="_blank">成都服务器托管</a>
            <a href="https://www.cdcxhl.cn/" target="_blank">云服务器</a>
            <a href="http://www.cdhuace.com/" target="_blank">广告设计制作</a>
            <a href="https://www.cdcxhl.com/sheji/chongqing.html" target="_blank">重庆网页设计</a>
            <a href="https://www.cdcxhl.com/zuo/chongqing.html" target="_blank">重庆做网站</a>
            <a href="https://www.cdcxhl.com/zhizuo/chongqing.html" target="_blank">重庆网站制作</a>
            <a href="">重庆网站建设</a>
            <a href="">重庆网站公司</a>
            <a href="">渝中网站制作</a>
            <a href="">重庆网站设计</a>
        </div>
    </div>
</div>
<div class="foot">
    <ul class="public-celan">
        <li>
            <a href="https://p.qiao.baidu.com/cps3/chatIndex?siteToken=6ce441ff9e2d6bedbdfc2a4138de449e&speedLogId=162260383240185e3_1622603832401_02407&eid=6256368&reqParam=%7B%22from%22%3A1%2C%22sessionid%22%3A%22-100%22%2C%22siteId%22%3A%2211284691%22%2C%22tid%22%3A%22-1%22%2C%22userId%22%3A%226256368%22%2C%22ttype%22%3A1%2C%22pageId%22%3A0%7D" target="_blank" class="a1 db tc">
                <img src="/Public/Home/img/icon-23.png" alt="" class="db auto">
                <span class="span-txt">在线咨询</span>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" class="a1 db tc">
                <img src="/Public/Home/img/icon-24.png" alt="" class="db auto">
                <span class="span-txt">电话咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="a1 db tc">
                <img src="/Public/Home/img/icon-25.png" alt="" class="db auto">
                <span class="span-txt">QQ咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=532337155&Site=&Menu=yes" class="a1 db tc public-yuyue-up">
                <img src="/Public/Home/img/icon-26.png" alt="" class="db auto">
                <span class="span-txt">预约顾问</span>
            </a>
        </li>
    </ul>
</div>
<div class="customer">
    <dl class="icon1">
        <dt>
            <a href="tencent://message/?uin=1683211881&Site=&Menu=yes">
                <i class="iconT"><img src="/Public/Home/img/QQ.png" alt=""></i>
                <p>在线咨询</p>
            </a>
        </dt>
    </dl>
    <dl class="icon2">
        <dt><i><img src="/Public/Home/img/weixin.png" alt=""></i><p>微信咨询</p></dt>
        <dd><img src="/Public/Home/img/ewm.png"></dd>
    </dl>
    <dl class="icon3">
        <dt><i><img src="/Public/Home/img/dianhua.png" alt=""></i><p>电话咨询</p></dt>
        <dd>
            <p>028-86922220(工作日)</p>
            <p>18980820575(7×24)</p>
        </dd>
    </dl>
    <dl class="icon4">
        <dt class="sShow">
            <a href="tencent://message/?uin=244261566&Site=&Menu=yes">
                <i><img src="/Public/Home/img/dengji.png" alt=""></i><p>提交需求</p>
            </a>
        </dt>
    </dl>
    <dl class="icon5">
        <dt class="gotop">
            <a href="#top">
                <i><img src="/Public/Home/img/top.png" alt=""></i><p>返回顶部</p>
            </a>
        </dt>
    </dl>
</div>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>