metalx1000

Use Webkit to download every file that loads on a webpage

Nov 16th, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import gtk, webkit, urllib2, os, random
  4.  
  5.  
  6. def update_buttons(view, frame, resource, request, response):
  7.     url=request.get_uri()
  8.     print url
  9.     u = urllib2.urlopen(url)
  10.     file = open(str(random.randint(0, 1000000000)),'w')
  11.     file.write(u.read())
  12.     file.close()
  13.  
  14. win = gtk.Window()
  15. win.connect('destroy', lambda w: gtk.main_quit())
  16. win.show()
  17.  
  18. box1 = gtk.HBox()
  19. win.add(box1)
  20.  
  21. web = webkit.WebView()
  22. web.connect("resource-request-starting", update_buttons)
  23. box1.pack_start(web)
  24.  
  25. web.open("http://www.winknews.com/Sports/2014-11-05/Naples-16-year-old-is-best-Flowboarder-in-the-world")
  26.  
  27. box1.show_all()
  28.  
  29. gtk.main()
Add Comment
Please, Sign In to add comment