【问题标题】:Extracting SVG from Webpage using Selenium Python使用 Selenium Python 从网页中提取 SVG
【发布时间】:2017-12-04 20:35:52
【问题描述】:

我正在尝试从该网站提取 高分辨率 图像:http://target.lroc.asu.edu/q3/ 考虑到它的纬度和经度。我已经编写了一个 python 脚本,它自动输入纬度和经度,但是如何使用 Python 和 selenium 在特定的纬度和经度处提取这个月球地图。此外,一旦提取,我希望将其保存为 .png 文件。

下面是导航到页面并自动输入 lat 和 long 值的代码。

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()

【问题讨论】:

  • 您要在哪个阶段截屏?您可以考虑分享您的确切手动步骤吗?谢谢
  • @DebanjanB 基本上我只是不想点击屏幕截图,而是在网站上提取高分辨率图像。这可能类似于从 Google 地图中提取地图的高分辨率部分。

标签: python selenium svg selenium-webdriver


【解决方案1】:

页面加载后,尤其是像这篇文章中的整页图像,可以通过单个 selenium 命令捕获图像并将其保存到文件中。

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

【讨论】:

  • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。
  • save_screenshot 函数下载低分辨率图像。我想要一个高分辨率的图像。这个函数把屏幕上的所有东西都截图了!!
  • 这行代码的语法也无效,因为 save_screenshot 需要一个字符串作为参数。
  • @RahulSharma 我将路径更改为更实用的字符串参数,而不是使用变量表示法。确保在您的系统上使用 有效 路径。回到你的实际需要。您是否需要放大更多才能获得所需的分辨率?简而言之,本网站不提供下载高分辨率图像来源的选项。您可以放大,然后对放大后的页面进行快照。
  • @RonNorris 这就是我目前正在做的,但我想知道是否有办法提取高分辨率 SVG 图像!!!!
猜你喜欢
  • 2021-12-05
  • 1970-01-01
  • 2020-09-24
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
  • 2019-04-12
相关资源
最近更新 更多