1
최근 Google 검색 결과에서 데이터를 크롤링하려고하는데 pyqt가 html로 javascript를 실행하고 최종 html 결과를 얻는 좋은 모듈 인 것 같습니다. 그러나 다른 웹 사이트의 경우 제대로 작동하는 것 같습니다. 그러나 Google 검색의 경우 항상 실패했습니다. 여기 예를 따르 그러나pyqt로 html 페이지의 최종 결과를 얻는 방법?
import sys
import time
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *
class Render(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self._loadFinished)
self.mainFrame().load(QUrl(url))
self.app.exec_()
def _loadFinished(self, result):
self.frame = self.mainFrame()
self.app.quit()
url1 = 'http://www.google.com/search?start=0&client=firefox-a&q=adidas&safe=off&pws=0&tbs=cdr%3A1%2Ccd_min%3A1%2F1%2F2002%2Ccd_max%3A1%2F1%2F2001&filter=0&num=10&access=a&oe=UTF-8&ie=UTF-8'
url2 = 'http://www.google.com/search?start=0&client=firefox-a&q=adidas&safe=off&pws=0&tbs=cdr%3A1%2Ccd_min%3A1%2F1%2F2009%2Ccd_max%3A7%2F1%2F2009&filter=0&num=10&access=a&oe=UTF-8&ie=UTF-8'
r = Render(url1)
html = r.frame.toHtml()
print type(html)
outfile = open('page.html','w')
outfile.write(html.toUtf8())
outfile.close()
print 'finished!'
, URL1와 URL2의 결과는 항상 같은 결과를 얻는다면, 나는 자바 스크립트를 사용하지 않는 경우 결과는 단지 동일합니다 http://webscraping.com/blog/Scraping-JavaScript-webpages-with-webkit/
코드는 크롬. 그럼 어떻게 처리해야합니까? Google 검색의 최종 html은 어떻게 가져올 수 있습니까?
이 영업 이익은 당신의 솔루션을 가지고 당신이 단지 동일한 코드를 게시 할 않았다 ... 당신을 했습니까? – ChrisArmstrong