所以我想用python腳本把一個網站的截圖:以網站的截圖與蟒蛇導致空白頁
#! /usr/bin/python
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
class Screenshot(QWebView):
def __init__(self):
self.app = QApplication(sys.argv)
QWebView.__init__(self)
self._loaded = False
self.loadFinished.connect(self._loadFinished)
def capture(self, url, output_file):
self.load(QUrl(url))
self.wait_load()
time.sleep(120)
# set to webpage size
frame = self.page().mainFrame()
self.page().setViewportSize(frame.contentsSize())
# render image
image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
frame.render(painter)
painter.end()
# print 'saving', output_file
image.save(output_file)
def wait_load(self, delay=0):
# process app events until page loaded
while not self._loaded:
self.app.processEvents()
time.sleep(delay)
self._loaded = False
def _loadFinished(self, result):
self._loaded = True
s = Screenshot()
s.capture('http://csgo-stats.com/maschs/', 'csgo-stats.png')
它幾乎每一頁上工作,但在現場CSGO-統計.com/maschs(這是我的個人資料頁面),它只是一個空白頁面,沒有頁面上的信息。當我在瀏覽器中打開該頁面時,需要幾秒鐘才能加載,並且可以正確顯示所有內容。結果是這樣的:
我使用的樹莓派和Python 2.7
您是否考慮過使用「Steam Web API」以官方認可的方式檢索信息而不是文字屏幕刮擦? –
這將是一個解決方案,但我沒有找到任何完整的python steam web api解決方案,並且該網站已經很好地顯示它。或者有沒有簡單的方法來使用Python的「Steam Web API」? – user3745172