title: Scraping SVG charts
body: <p>I am trying to scrape the following svg's from the following link: </p>
  
  <p><a href="https://finance.yahoo.com/quote/AAPL/analysts?p=AAPL" rel="nofollow noreferrer">https://finance.yahoo.com/quote/AAPL/analysts?p=AAPL</a></p>
  
  <p>The portion I am trying to scrape is as follows: </p>
  
  <p><a href="https://i.stack.imgur.com/BemwZ.png" rel="nofollow noreferrer">Images Here</a></p>
  
  <p>I do not need the words of the chart (just the graphs themselves). However, I have never scraped an svg image before and i'm not sure if it is possible. I looked around but could not find any useful python packages to directly do this. </p>
  
  <p>I know that I can take a screenshot of the image with python using selenium and then use PIL to crop it and save it as an svg, but I am wondering if there is a more direct way to grab these charts off the page. Any useful packages or implementations would be helpful. Thank you.  </p>
  
  <p>Edit: Got some down votes but not sure why Here is how I would implement it in my way.. </p>
  
  <pre><code>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')
  </code></pre>
  
  <p>I would then use the crop function in PIL to take the images out of the charts. </p>