0

I am taking a screenshot with phantomjs that is coming out blurry. Is it possible to get better resolution of a screenshot so that it looks like the actual page?

driver = webdriver.PhantomJS() 
driver.set_window_size(a, b)
driver.get('www.page.com')
driver.save_screenshot('screenpic.png')   
screen =  driver.get_screenshot_as_png()
im = Image.open(StringIO.StringIO(screen))
#I then set a region to crop called wndw 
region = im.crop(wndw)

How can I make the page sharper?

hellowrld
  • 53
  • 1
  • 8

2 Answers2

0

The page gets focus information through the onfocus and onblur callbacks in the window object, which you can call yourself:

browser.execute_script("window.onfocus()")

If a specific element needs to be focused, try either:

browser.execute_script("document.getElementById('id').focus()") browser.execute_script("document.getElementById('id').click()")

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
  • So, I am downloading the entire page to just crop one svg element. This comes out really blurry. Is it possible to focus the entire page before I crop and not just focus the element? I added some code in my edit. – hellowrld Nov 07 '16 at 20:26
  • To be sure, is screenpic.png blurry, or the region you end up cropping? (or ignore if not applicable given any new answer)... i.e. the initial screenshot wasn't blurry for me – ballade4op52 Nov 07 '16 at 20:53
  • The page is blurry, it seems a little pixalized so when I crop it it still is blurry. I am trying to scrape this svg chart from finance.yahoo.com/quote/AAPL/analysts?p=AAPL under the tab reccomendation trends on the right side. I am using a screenshot because I don't know another way to grab the svg – hellowrld Nov 07 '16 at 23:23
0

From the comment to @Phillip's answer it seems you don't actually want the entire page, you want to get an image of one SVG file.

Why don't you get the SVG file and convert it to an image directly? According to this answer you can use Python rsvg to render SVG files.

If you don't know the SVG's URL you can use Selenium to find it out, then download it from Python and render to PNG.

Community
  • 1
  • 1
zmbq
  • 38,013
  • 14
  • 101
  • 171
  • So, say we wanted to scrape this svg chart from http://finance.yahoo.com/quote/AAPL/analysts?p=AAPL under the tab reccomendation trends on the right side. I can't seem to find the url when I inspect element. If I wanted to download just this chart will that work? – hellowrld Nov 07 '16 at 23:24
  • The data-reactid = '.6oei8dvzzo.0.$0.0.0.3.1.$main-0-Quote-Proxy.$main-0-Quote.2.1.$trends.1.0' and the class='ratings-chart' I can't find the web link to this though through selenium – hellowrld Nov 07 '16 at 23:30