使用Selenium Python从网页中提取SVG
我正试图从这个网站上提取高分辨率的图像:给定它的纬度和经度。我已经编写了一个python脚本,可以自动输入纬度和经度,但是如何使用python和selenium提取特定纬度和经度的月球地图呢。此外,提取后,我希望将其另存为.png文件 下面是导航到页面并自动输入lat和long值的代码使用Selenium Python从网页中提取SVG,python,selenium,svg,selenium-webdriver,Python,Selenium,Svg,Selenium Webdriver,我正试图从这个网站上提取高分辨率的图像:给定它的纬度和经度。我已经编写了一个python脚本,可以自动输入纬度和经度,但是如何使用python和selenium提取特定纬度和经度的月球地图呢。此外,提取后,我希望将其另存为.png文件 下面是导航到页面并自动输入lat和long值的代码 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.com
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命令捕获图像并将其保存到文件中
driver.save_screenshot('/home/rebel/images/myscreen.png')
虽然此代码可能会回答此问题,但提供有关此代码回答此问题的原因和/或方式的附加上下文可提高其长期价值。save_screenshot函数可下载低分辨率图像。我想要一张高分辨率的图像。这个函数将截取屏幕上所有内容的屏幕截图!!此外,这行代码的语法无效,因为save_屏幕截图需要一个字符串作为参数。@RahulSharma我将路径改为更实用的字符串参数,而不是使用变量表示法。确保使用系统上的有效路径。回到你的实际需要。是否需要放大更多以获得所需的分辨率?简而言之,本网站不提供下载高分辨率图像源的选项。您可以放大,然后拍摄缩放页面的快照。@RonNorris这就是我目前正在做的,但我想知道是否有办法提取高分辨率SVG图像!!!!你打算在哪个阶段拍摄截图?你能考虑与你的手动步骤分享吗?Thanks@DebanjanB基本上我只是不想点击屏幕截图,而是在网站上提取高分辨率图像。这可能类似于从谷歌地图中提取地图的高分辨率部分。