Based on this period of time, Guangzhou's oil price change is relatively large, so I myself view the price of the site also increased, but as aProgrammerIsn't that an insult?? Can use the code to achieve why use manpower??? So I made a simple Python script to climb the oil price information, and later found that the execution of scripts or more trouble, on a regular basis to crawl the information sent to the corresponding public number! Words not much to say, directly on the script.
(ENV1) ? python_scripts cat youjia_wechat.py#!/usr/bin/python#-*- coding:utf-8 -*-#__author__ == ' chenmingle ' import requestsimport jsonimport sysreload (SYS) Sys.setdefaultencoding (' Utf-8 ') import urllib3import timeimport urllibimport reurl = r ' http://youjia.chemcp.com/guangdong/guangzhoushi.html ' res = urllib.urlopen (URL) HTML = res.read (). Decode (' gb2312 ') par = ' ( ) (. *?) (<br />) ' Web = re.search (par,html). Group (2) web = web.split (' ', 1) [0] Cml = web.replace (' <font color= ' Red > ', ': ') cml = cml.replace (' </font> ', ' ' Cml = cml.replace (', ', ' \ n ') cml = cml.replace (': ', ' \ n ', 1) cml = cml.replace (', ', ') \ n ') print cmlclass wechat: def __init__ (Self,corpid,secret): url = ' https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s ' % (Corpid,secret) res = self.url_req (URL) self.token = res["Access_token"] Def url_req (self,url): requests.packages.urllib3.disable_ Warnings () req = requests.get (Url, verify=False) res = json.loads (Req.text) return res def send_message (self,user,content): url = "Https://qyapi.weixin.qq.com/cgi-bin/message/send? access_token=%s " % self.token data = { "Touser": user, "Msgtype": "text", "Agentid": 1000002, "Text" : { "Content": content }, "safe": "0" } &nbSp;requests.packages.urllib3.disable_warnings () res = requests.post (Url,json=data, verify=false) if Json.loads (res.content) [' errmsg '] == ' OK ': return "send message sucessed" else: return reslocaltime = time.strftime ("%y-%m-%d %h:%m:%s") a = "Guangzhou Oil Price Information:" if __name__ == "__ main__ ': user = ' @all ' title = a msg = cml content = a + ' \ n ' + cml get_token = wechat (' wxf****** ', ' **********pfou7***8 ') print get_token.send_messAge (User, content)
Finally add crontab on the timed execution script:
(ENV1)? Python_scripts CRONTAB-L45 8 * * */usr/local/bin/python/home/python_scripts/youjia_wechat.py >/dev/null 2>& ; 1
On the public number, you'll know the daily oil price.
Python beginners, so look at the great gods and many advice
Python Simple crawl oil price information sent to the public number