Python實現利用微博遠程關機

來源:互聯網
上載者:User

標籤:

利用爬蟲,定時擷取微博內容。用正則匹配指令

 

 

 

#檢測微博內容實現自動操作電腦#2015/3/16import osimport reimport urllib.requestimport timeclass sCrapy:    def __init__(self,url):        self.url = url    def get_html(self):        self.req = urllib.request.Request(self.url)        self.req.add_header(‘User-Agent‘,‘Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36‘)        self.html = urllib.request.urlopen(self.req).read().decode("utf-8")    def find_message(self,Regex = None,target=None):        print("I AM Online")        self.Getlist = re.search(Regex,self.html)        self.get_instruction = self.Getlist.groups()        self.get_time = False        if re.search(r"剛剛",self.html):            self.get_time = True            print("right now matched")        elif re.search(r"[0-9]{1,2}分鐘前",self.html):            self.get_time = True            print("minute matched")        #get_time = re.search(r"1分鐘前",self.html) if re.search("剛剛")        #print(get_time)        print("Before run the get_time is ",self.get_time)        if re.search(r‘shutdown‘,self.get_instruction[0]) and self.get_time:            #print("Before judge the shutdown_a is ",shutdown_a)            #print("\nBefore judge the shutdown_t is ",shutdown_t)            print("I search the %s"%self.get_instruction[0])            if re.search(r"-a",self.get_instruction[0]) and target[0] == False:                print("取消關機")                os.system("shutdown -a")                self.get_time = False                target[0] = True                target[1] = False                print("Now the get_time is ",self.get_time)            elif target[1] == False and re.search(r"-t",self.get_instruction[0]):                self.time = str(re.findall(r"[0-9]+",self.get_instruction[0])[0])                self.shutdown = "shutdown "+"-s "+"-t "+self.time                print("親,要關機了喲")                #print(shutdown)                os.system(self.shutdown)                self.get_time = False                target[1] = True                target[0] = False                print("Now the get_time is ",self.get_time)                if __name__ == ‘__main__‘:    url = "http://t.qq.com/devil19951104"    Craw = sCrapy(url)    target = []    target.append(False)    target.append(False)    #target = False    while True :        Craw.get_html()        try:            Craw.find_message(r‘([a-z]+ -[a-zA-Z]{1} {0,1}[0-9]*)‘,target)        except:            print("親,還沒有命令或者你的命令已經開始執行啦~~")        print("Already")        time.sleep(600)

 

Python實現利用微博遠程關機

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.