Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import requests
  2. import sys
  3. import time
  4. from PyQt4.QtCore import *
  5. from PyQt4.QtGui import *
  6. from PyQt4.QtWebKit import *
  7.  
  8. s = requests.session()
  9. login_data = dict(username='bybo', password='118932')
  10. s.post('https://rstforums.com/forum/login', data=login_data)
  11.  
  12. class Screenshot(QWebView):
  13. def __init__(self):
  14. self.app = QApplication(sys.argv)
  15. QWebView.__init__(self)
  16. self._loaded = False
  17. self.loadFinished.connect(self._loadFinished)
  18.  
  19. def capture(self, url, output_file):
  20. self.load(QUrl(url))
  21. self.wait_load()
  22. # set to webpage size
  23. frame = self.page().mainFrame()
  24. self.page().setViewportSize(frame.contentsSize())
  25. # render image
  26. image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
  27. painter = QPainter(image)
  28. frame.render(painter)
  29. painter.end()
  30. print 'Saving...', output_file
  31. image.save(output_file)
  32.  
  33. def wait_load(self, delay=0):
  34. # process app events until page loaded
  35. while not self._loaded:
  36. self.app.processEvents()
  37. time.sleep(delay)
  38. self._loaded = False
  39.  
  40. def _loadFinished(self, result):
  41. self._loaded = True
  42.  
  43. s = Screenshot()
  44. ww = raw_input("Link-ul la care sa faci screen tarane: ")
  45. s.capture(ww, 'website.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement