selenium screenshot - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: selenium screenshot (/thread-2148.html) Pages:
1
2
|
selenium screenshot - hai001 - Feb-22-2017 Hello Everyone, Can you share code for auto opening 6 websites and take screen shots of each website at particular area. Screen shot of the area and url are fixed. Screen shots to be saved in jpeg/png. Kindly help if this can possible. Thanks. RE: Code for website url and take screen shot of specific area on websire - Yoriz - Feb-22-2017 Did you mean for this to be on the jobs section (moved there unless you have code you want help with) RE: Code for website url and take screen shot of specific area on websire - hai001 - Feb-22-2017 hi Yoriz, I didnt get you ?... is there any solution for my query ? hi Yoriz, yeah.. Got it. I will come back with code.Thanks RE: Code for website url and take screen shot of specific area on websire - wavic - Feb-22-2017 There is a solution. Selenium + pyautogui/pyscreenshot modules. I never used selenium so I can't provide a working example RE: Code for website url and take screen shot of specific area on websire - buran - Feb-22-2017 (Feb-22-2017, 01:20 PM)wavic Wrote: There is a solution. Selenium + pyautogui/pyscreenshot modules. I never used selenium so I can't provide a working exampleactually you can do this with Selenium + PhantomJS (that will be used with Selenium anyway), no need to add extra modules. RE: Code for website url and take screen shot of specific area on websire - wavic - Feb-22-2017 I completely forgot PhantomJS Don't remember that it's included in Selenium RE: Code for website url and take screen shot of specific area on websire - metulburr - Feb-22-2017 from selenium import webdriver driver = webdriver.PhantomJS('/home/metulburr/phantomjs') #http://phantomjs.org/download.html driver.set_window_size(1920,1080) driver.get('http://www.google.com') driver.save_screenshot('out.png') driver.quit()where the path is to wherever the webdriver downloaded resides on your computer out.png [attachment=127] Im sure you can get the element location, and crop the image to that location. Not sure exactly as i never had to do that before. RE: Code for website url and take screen shot of specific area on websire - snippsat - Feb-22-2017 (Feb-22-2017, 03:01 PM)wavic Wrote: I completely forgot PhantomJS Smile Don't remember that it's included in SeleniumIt's not included in Selenium,have download PhantomJS and give path to executable as show over. RE: Code for website url and take screen shot of specific area on websire - metulburr - Feb-22-2017 here is a method of using selenium to get the screenshot and the elements location, then PIL to crop it via its location and size to get just the element and crop out the rest So here i am trying to extract the google image via a full screenshot... from selenium import webdriver from PIL import Image FILENAME = ' screenshot.png' driver = webdriver.PhantomJS('/home/metulburr/phantomjs'); driver.set_window_size(1920,1080) driver.get('http://google.com') element = driver.find_element_by_tag_name('img') location = element.location size = element.size driver.save_screenshot(FILENAME) driver.quit() im = Image.open(FILENAME) left = int(location['x']) top = int(location['y']) right = int(location['x'] + size['width']) bottom = int(location['y'] + size['height']) im = im.crop((left, top, right, bottom)) im.save(FILENAME)screenshot.png [attachment=128] RE: Code for website url and take screen shot of specific area on websire - hai001 - Feb-25-2017 Dear metulburr, Appreciate your reply and solution. Could you please help me in knowing what are all the apps that we needed to run this code. Thanks in advance for your help |