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
  • 相关阅读:
    cytoscape-d3-force api
    Python基础编程 模块的引入与定义
    更改Ubuntu内核版本
    Jupyter Notebook默认路径修改
    YJZH 前端部署记录 CentOS+Nginx+Vue
    dotnet core webapi centos 服务自启动
    Linux修改时区
    空间数据实战(1)——MySQL
    记录window.sessionStorage的一个小坑
    ElementUI默认表单项el-form-item间距修改
  • 原文地址:https://www.cnblogs.com/0056a/p/8758939.html
Copyright © 2011-2022 走看看