今天工作的时候突然遇到个问题,就尝试着按照领导所说要天马行空的想东西,于是那点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,在加上鼠标模拟操作,嗯,一定可以做出相当不错的东西。