import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
start_url = 'http://searchex.yixun.com/?YTAG=1.100090000'
def save_file(data,file='temp.txt'):
f = open(file,'w')
f.write(data)
f.close()
web = None
def onDone():
f = open('scrapy.html','w')
page = web.page().mainFrame().toHtml().toUtf8().data()
f.write(page)
f.close()
print "Done ..."
e = web.page().mainFrame().documentElement().findFirst("h3[class=m_classbox_hd]")
print e.tagName()
#print dir(e)
print e.toPlainText().toUtf8().data() #.decode('gbk') #.decode('utf-8') #.encode('utf-8')
save_file(e.toPlainText().toUtf8().data())
def onStart():
print "Started..."
app = QApplication(sys.argv)
web = QWebView()
web.page().mainFrame().loadStarted.connect(onStart)
web.page().mainFrame().loadFinished.connect(onDone)
web.load(QUrl(start_url))
#print web.page().mainFrame().toHtml()
print 'end'
web.show()
sys.exit(app.exec_())