python 爬取svg数据_抓取SVG图表
我試圖從以下鏈接中獲取以下svg:
我要刮的部分如下:
我不需要圖表中的文字(只需要圖表本身)。但是,我以前從來沒有抓取過svg圖像,我不確定這是否可能。我環顧四周,但找不到任何有用的python包來直接執行此操作。在
我知道我可以用python使用selenium截圖圖像,然后使用PIL裁剪它并將其保存為svg,但我想知道是否有更直接的方法從頁面上獲取這些圖表。任何有用的包或實現都會很有幫助。謝謝您。在
編輯:得到了一些反對票,但不確定為什么我會以我的方式來實施它。。在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()
# 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('https://finance.yahoo.com/quote/AAPL/analysts?p=AAPL', 'yhf.png')
然后我將使用PIL中的crop函數將圖像從圖表中取出。在
總結
以上是生活随笔為你收集整理的python 爬取svg数据_抓取SVG图表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql有nvarchar类型_mys
- 下一篇: python爬虫多进程_Python爬虫