Skip to content

Instantly share code, notes, and snippets.

@jollychang
Created July 20, 2011 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jollychang/1094223 to your computer and use it in GitHub Desktop.
Save jollychang/1094223 to your computer and use it in GitHub Desktop.
automation leech and downlaod with webdriver
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time, os, string
from selenium import webdriver
def downloader(link, host='http://shimory.com/'):
file = open('/Users/jollychang/Downloads/firebug-1.7.3.xpi')
fp = webdriver.FirefoxProfile()
fp.add_extension(file)
b = webdriver.Firefox(fp)
l = link
h = host
b. get(h)
print "clean the input box"
b.find_element_by_id('url').clear()
print "type download link"
b.find_element_by_id('url').send_keys(l)
print "submit form"
#b.find_element_by_id('form').submit()
print b.title
b.find_element_by_tag_name('form').submit()
print "submit form successfully"
print b.title
while not 'successfully' in b.page_source:
title = b.title
print title.rsplit(" ")[0]
if "The link you've requested has already finished before this." in b.page_source:
print "The link you've requested has already finished before this."
break
time.sleep(1)
dl = b.find_element_by_xpath("id('download-information')/p/a").get_attribute('href')
b.quit()
print dl
dl = string.replace(dl, ' ', '%20')
print dl
os.system('wget %s -a log.log' % dl)
if __name__=='__main__':
file = open('dl.txt')
for link in file.readlines():
downloader(link)
file.close()
print "file close"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment