python中sendkeys.sendkeys_python的webbrowser模块和SendKeys模块
今天工作的時候突然遇到個問題,就嘗試著按照領導所說要天馬行空的想東西,于是那點scrapy的代碼逐漸忘了的差不多了,想到用迅雷去下載一些東西,迅雷不知道怎么回事,但知道一點,他監控計算機瀏覽器,那么我想下載什么東西的時候,可以去獲得一個遵循迅雷協議的地址,使用webbrowser模塊打開這個地址就能調用迅雷做我自己的事情了。
import webbrowser
webbrowser.open('http://www.google.com.hk/')
我用的是windows操作系統,關于這個模塊,其實有更簡單,更原始的提供給我們使用:
if sys.platform[:3] == "win":
class WindowsDefault(BaseBrowser):
def open(self, url, new=0, autoraise=1):
try:
os.startfile(url)
except WindowsError:
# [Error 22] No application is associated with the specified
# file for this operation: ''
return False
else:
return True
_tryorder = []
_browsers = {}
# First try to use the default Windows browser
register("windows-default", WindowsDefault)
# Detect some common Windows browsers, fallback to IE
iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
"Internet Explorer\\IEXPLORE.EXE")
for browser in ("firefox", "firebird", "seamonkey", "mozilla",
"netscape", "opera", iexplore):
if _iscommand(browser):
register(browser, None, BackgroundBrowser(browser))
操作系統不一樣,在這里將有區別了,其實最有用的就一句,os.startfile(url),也能獲得剛才我們使用webbrower模塊open的效果,只不過推薦是使用webbrower的,因為他更具有兼容性。
想到這里,在加上鍵盤操作模塊,SendKeys,在加上鼠標模擬操作,嗯,一定可以做出相當不錯的東西。
總結
以上是生活随笔為你收集整理的python中sendkeys.sendkeys_python的webbrowser模块和SendKeys模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python人脸识别训练模型生产_深度学
- 下一篇: python subprocess po