2017-02-07 14 views
0

私は産業用バーコードスキャナを持っています。WebブラウザでPythonを開いてQRコードを開きます

私はURIを含むQRコードをスキャンしたいので、そのURIをマシンのデフォルトブラウザで自動的に開くべきです。

私は、次のコードを持っている:

# -*- coding: utf-8 -*- 

import pyHook 
import pythoncom 
import re 
import webbrowser 



endDomains = ".de|.com|.net|.org|.edu|.gov|.mil|.aero|.asia|.biz|.cat|.coop|.info|.int|.jobs|.mobi|.museum|.name|.post|.pro|.tel|.travel".split("|") 
chars = "" 
def pressed_chars(event): 
    global chars 
    if event.Ascii: 
     char = chr(event.Ascii)  
     if event.Ascii == 3: 
      quit() 
     else: 
      chars += char 
      try: 
       urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars) 
       print(urls) 
      except: 
       urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars) 
       print(urls) 
      if len(urls) > 0: 
       for url in urls: 
        for i in endDomains: 
         if i in url: 


          webbrowser.open_new_tab(url) 

          chars = "" 
          break 



proc = pyHook.HookManager() 
proc.KeyDown = pressed_chars 
proc.HookKeyboard() 
pythoncom.PumpMessages() 

をしかし、それは私のブラウザを開いていません。 誰でも助けてくれますか?

オペレーティングシステムは、Python 2.7 + PyhookがインストールされたWindows 10です。

Python output

答えて

0

次のPythonコードは、私が欲しいものでした:それは、Internet ExplorerでWebサイトを開きます

import pyHook 
import pythoncom 
import httplib 
import getpass 
import shutil 
import sys 
import re 
import webbrowser 

endDomains = "end|thisistheend|.com".split("|") 

chars = "" 

def OnKeyBoardEvent(event): 
    global chars 

    if event.Ascii: 
     char = chr(event.Ascii) 
     if event.Ascii == 3: 
     quit() 
    else: 
     chars += char 
     try: 
      urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars) 
      print(urls) 
     except: 
      urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', chars) 
      print(urls) 
     if len(urls) > 0: 
      for url in urls: 
       for i in endDomains: 
        if i in url: 
         webbrowser.open_new_tab(url) 
         chars = "" 
         break 



hook_manager = pyHook.HookManager() 
hook_manager.KeyDown = OnKeyBoardEvent 
hook_manager.HookKeyboard() 
pythoncom.PumpMessages() 

ときの構文でユーザータイプ: https://website.com

関連する問題