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://hxwzsj.com/article/dhcoso.html">http://hxwzsj.com/article/dhcoso.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/pocdpe.html">php如何判断电子邮件是否正确</a>
                </li><li>
                    <a href="/article/pocdge.html">golang的字符串操作</a>
                </li><li>
                    <a href="/article/pocdis.html">Android开发之绘制平面上的多边形功能分析</a>
                </li><li>
                    <a href="/article/pocdjj.html">vue解决循环引用组件报错的问题</a>
                </li><li>
                    <a href="/article/pocdpd.html">faceu有哪些功能</a>
                </li>        </ul>
    </div>
</div>
<div class="footer2">
    Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14 <br />友情链接:
    <a href="http://seo.cdkjz.cn/wangzhan/" target="_blank">网站制作公司 </a><a href="http://www.ybwzjz.com/" target="_blank">宜宾网站设计 </a><a href="http://m.cdcxhl.com/muban.html" target="_blank">成都模版网站建设 </a><a href="http://m.cdcxhl.com/" target="_blank">成都网站制作 </a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站建设 </a><a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">成都定制网站建设 </a><a href="http://m.cdcxhl.cn/H5/" target="_blank">响应式网站建设 </a><a href="http://m.cdcxhl.cn/seo/" target="_blank">营销网站建设 </a><a href="https://www.cdcxhl.com/" target="_blank">成都网站制作 </a><a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">定制网站设计 </a><a href="http://www.cdxtjz.com/" target="_blank">网站制作 </a><a href="http://www.kswcd.com/mobile/" target="_blank">手机网站建设 </a><a href="https://www.cdxwcx.com/" target="_blank">成都网站制作 </a><a href="http://www.cdweb.net/" target="_blank">自适应网站建设 </a><a href="http://www.cdxwcx.cn/" target="_blank">成都网站设计 </a><a href="https://www.cdcxhl.com/sheji/chengdu.html" target="_blank">四川成都网站设计 </a><a href="http://www.cqcxhl.com/service/" target="_blank">品牌网站建设 </a><a href="https://www.cdxwcx.com/" target="_blank">成都网站设计公司 </a><a href="http://m.cdcxhl.cn/shop/" target="_blank">成都商城网站建设 </a><a href="https://www.cdxwcx.com/wangzhan/mbqiye.html" target="_blank">成都企业网站制作 </a><a href="http://www.cxjianzhan.com/baojia/" target="_blank">网站建设费用 </a><a href="http://m.xwcx.net/" target="_blank">H5网站制作 </a></div>

</body>
</html>
<script src="/Public/Home/js/wow.min.js"></script>
<script>
    if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
        new WOW().init();
    };
</script>
<div class="sidebar">
    <ul>
        <li><a href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=hxwzsj.com&menu=yes" target="_blank"><img src="/Public/Home/images/right_qq.png" /></a></li>
        <li><a href="http://wpa.qq.com/msgrd?v=3&uin=1683211881&site=hxwzsj.com&menu=yes" target="_blank"><img src="/Public/Home/images/qq.png" /></a></li>
        <li class="tel"><a href="tel:028-86922220"><img src="/Public/Home/images/right_tel.png" /></a></li>
        <div class="wx">
            <span class="weixin"><img src="/Public/Home/images/weixin.jpg"><br> 微信扫一扫在线咨询</span>
        </div>
        <li><a class="fx" href="#hero"><img src="/Public/Home/images/right_up.png" /></a></li>
    </ul>
</div>
<script type="text/javascript">
    $(function () {
        $('.sidebar .fx').click(function () {
            $('html,body').animate({
                scrollTop: '0px'
            }, 800);
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#fancybox-manual-b").click(function () {
            $.fancybox.open({
                href: 'map.html',
                type: 'iframe',
                padding: 5
            });
        })
    });
</script>
<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>