使用Selenium Python从网页中提取SVG [英] Extracting SVG from Webpage using Selenium Python

查看:755
本文介绍了使用Selenium Python从网页中提取SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下网站提取高分辨率图片: http ://target.lroc.asu.edu/q3/给出其纬度和经度.我已经编写了一个python脚本,该脚本会自动输入纬度和经度,但是如何使用Python和硒在特定的纬度和经度处提取此月球图.另外,一旦提取,我希望将其另存为.png文件.

I am trying to extract High Resolution image from this website : http://target.lroc.asu.edu/q3/ given its latitude and longitude. I have written a python script which inputs the Latitude and Longitude automatically, but how do I extract this Lunar Map at that specific latitude and longitude using Python and selenium. Also, once extracted, I wish to save it as a .png file.

下面是导航到页面并自动输入经度和纬度值的代码.

Below is the code that navigates to the page and enters lat and long values automatically.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from PIL import Image
import time 

#Taking the inputs from USER
latitude = input('Enter the Latitude : ')
longitude = input('Enter the longitude : ')

#Below is to remove the toolbar and open chrome and visit the webpage 
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://target.lroc.asu.edu/q3/#')

full = driver.find_element_by_xpath('//div[@class="links"]')
full2 = full.find_element_by_xpath('//span[@class="smallHelpBox"]')
full3 = full2.find_element_by_xpath('//a[@class="fullscreen mapbutton"]').click()

arrow2 = driver.find_element_by_xpath('//div[@class="zoomSelectWrapper mapbutton"]').click()
arrow3 = driver.find_element_by_xpath('//ul[@class="zoomSelect ui-menu ui-widget ui-widget-content ui-corner-all"]')
arrow4 = driver.find_element_by_xpath('//li[@class="ui-menu-item"]')
arrow5 = driver.find_element_by_xpath('//a[@id="ui-id-58"]')
arrow5.click()

arrow = driver.find_element_by_xpath('//div[@id="OpenLayers.Control.MousePosition_19" and @class="olControlMousePosition olControlNoSelect"]')
arrow.click()
trial = driver.find_element_by_xpath('//div[@class="recenterWrapper"]')

trial.find_element_by_xpath('//input[@class = "latbox"]').send_keys(str(latitude)) 
trial.find_element_by_xpath('//input[@class = "lonbox"]').send_keys(str(longitude)) 
trial.find_element_by_xpath('//a[@class = "recenterBtn qm-icon icon-recenter"]').click()
arrow.click()

推荐答案

页面加载后,尤其是整页图像(如本文中的图像),可以通过单个selenium命令捕获该图像并将其保存到文件中.

After a page is loaded, especially a full page image like the one in this post, the image can be captured and saved to a file by a single selenium command.

driver.save_screenshot('/home/rebel/images/myscreen.png')

这篇关于使用Selenium Python从网页中提取SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆