-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebkit_render.py
More file actions
43 lines (32 loc) · 928 Bytes
/
webkit_render.py
File metadata and controls
43 lines (32 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
try:
from PySide.QtGui import *
from PySide.QtCore import *
from PySide.QtWebKit import *
except ImportError:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *
import lxml.html
import downloader
def direct_download(url):
download = downloader.Downloader()
return download(url)
def webkit_download(url):
app = QApplication([])
webview = QWebView()
webview.loadFinished.connect(app.quit)
webview.load(url)
app.exec_() # delay here until download finished
return webview.page().mainFrame().toHtml()
def parse(html):
tree = lxml.html.fromstring(html)
print tree.cssselect('#result')[0].text_content()
def main():
url = 'http://example.webscraping.com/dynamic'
parse(direct_download(url))
parse(webkit_download(url))
return
print len(r.html)
if __name__ == '__main__':
main()