码迷,mamicode.com
首页 > 其他好文 > 详细

使用正则表达式,取得点击次数,函数抽离

时间:2018-04-09 23:06:20      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:ret   count   正则   http   als   encoding   hat   dig   .gz   

1.import re;
def isEmailAccount(str):
    if(re.match("\w*@\w*(\.\w{2,3}){1,3}$",str)):
        return True
    else:
        return False
print(isEmailAccount(‘123sdf_sd@qq.com.cm‘))
print(isEmailAccount(‘123sdf_sd@qq‘))


2.import re;
import requests
newurl=‘http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0404/9183.html‘
res = requests.get(newurl)
res.encoding=‘utf-8‘
tel=re.findall("(\d{3,4}) *- *(\d{7,8})",res.text)


3.import re;
str="""In this year‘s government work report, Premier Li Keqiang frequently referred to internet-related concepts, like Internet Plus, artificial intelligence, and Digital China, and noted that the Chinese government will give priority to "providing more and better online content"."""
a=re.split(‘[\s,.?\" ]+‘,str)
print(a)



6.import re
import requests
url="http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0404/9183.html"
newId=re.search("/(\d*).html$",url).group(1)
print(newId)
clickUrl ="http://oa.gzcc.cn/api.php?op=count&id={}&modelid=80".format(newId)
print(clickUrl)
resc = requests.get(clickUrl)
num = re.search(".html\(‘(\d*)‘\)",resc.text).group(1)
print(num)

使用正则表达式,取得点击次数,函数抽离

标签:ret   count   正则   http   als   encoding   hat   dig   .gz   

原文地址:https://www.cnblogs.com/AAAAAAAA/p/8763250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!