zoukankan      html  css  js  c++  java
  • 使用正则表达式,取得点击次数,函数抽离

    1.

    import re
    a = '^(w)+([.\_-]w+)*@(w)+((.w{2,3}){1,3})$'
    b = '01435848@qq.com'
    if re.match(a,b):
        print('suc')
    else:
        print('error')

    2.

    import re
    a = '''020-88864444'''
    b = re.match(r'^(d{3,4})-(d{6,8})$',a)
    if b:
        print(b.group(0))
    else:
        print('error')

    3.

    str='''Cellphone is very popular in our life.It is a useful tool for us to communicate with others wherever he or she is .We can also send messages to them .Apart from these,the cellphones can also be used as an alarm clock.In a word,cellphones are very useful to our life.But some people abused the cellphones .They use them to play games ,which is bad for the eyes and will waste much time .What's worse ,some people use them to send some illegal messages to others ,which can bring us much trouble.
    So in my opinion ,we should make full use of the cellphone ,only in that way can we benefit from them. '''
    
    sep = ''',.:;?!-_'''
    for t in sep:
        str = str.replace(t,'')
    
    a = str.lower().split()
    print(a)

    4.

    import re
    a ='http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0404/9183.html'
    re.match('http://news.gzcc.cn/html/2018/xiaoyuanxinwen_(.*).html',a).group(1).split('/')[-1]
    
    print(a)

    5.

    6.

    import requests
    from bs4 import BeautifulSoup
    from datetime import datetime
    
    
    clickUrl = 'http://oa.gzcc.cn/api.php?op=count&id=9183&modelid=80'
    resc = requests.get(clickUrl)
    a = resc.text.split('.html')[-1].lstrip("('").rstrip("');")
    
    print(a)

    7.

    def getClickCount(newsUrl):
        newsId = re.search('\_(.*).html', newsUrl).group(1).split('/')[-1]
        clickUrl = 'http://oa.gzcc.cn/api.php?op=count&id={}&modelid=80'.format(newsId)
        resc = requests.get(clickUrl).text.split('.html')[-1].lstrip("('").rstrip("');")
        print('编号:'+newsId)
        print(clickUrl)
        print('点击数:'+resc)
        return
     
    getClickCount('http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0404/9183.html')
     
    8.
    def getNewDetail(newsUrl):
        res = requests.get(newsUrl)
        res.encoding = 'utf-8'
        soupd = BeautifulSoup(res.text, "html.parser")
        info = soupd.select('.show-info')[0].text
        dt = info.lstrip('发布时间')[1:20]
        dt = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
        print(dt)
        = info.find('来源:')
        = info.find('作者:')
        = info.find('审核:')
        sy = info.find('摄影:')
        if i > 0:
            = info[info.find('来源:'):].split()[0].lstrip('来源:')
            print('来源:'+s)
        if z > 0 :
            = info[info.find('作者:'):].split()[0].lstrip('作者:')
            print'作者:' + z)
        if c > 0 :
            = info[info.find('审核:'):].split()[0].lstrip('审核:')
            print'审核:' + c)
        if sy > 0:
            sy = info[info.find('摄影:'):].split()[0].lstrip('摄影:')
            print('摄影:'+ sy)
        # print('正文:' + soupd.select('.show-content')[0].text)
        # print(getClickCount(newsUrl))
        return
  • 相关阅读:
    解决HttpServletResponse输出的中文乱码问题
    Java微信公众平台开发(四)--回复消息的分类及实体的创建
    Java微信公众平台开发(三)--接收消息的分类及实体的创建
    Java微信公众平台开发(二)--微信服务器post消息体的接收
    Java微信公众平台开发(一)--接入微信公众平台
    ****创业者必看:黄太吉商业计划书完整版
    php变量的几种写法
    **对比$_POST、$GLOBALS['HTTP_RAW_POST_DATA']和file_get_contents('php://input')
    CodeIgniter报错: You must use the "set" method to update an entry
    2016年最新苹果开发者账号注册申请流程最强详解!
  • 原文地址:https://www.cnblogs.com/0056a/p/8758939.html
Copyright © 2011-2022 走看看