使用正则表达式,取得点击次数,函数抽离
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)