将来自维基百科的 SVG 文件保存为 python 中的 SVG
Save SVG File from wikipedia as SVG in python
目标:
从维基百科保存 SVG
要求:
需要自动化
目前我正在使用 selenium 获取一些其他信息,我尝试使用这样的 python 脚本来提取 svg 但提取的 SVG 文件渲染时出错。
编辑:
使用requests时出现同样的错误,可能与上传的文件wikipedia有关?
错误代码:
Errorcode for svg file
稍后渲染部分svg:
Rendered part of SVG
它应该是什么样子:
Map;Oslo zoomed out
代码imageEctractSingle.py:
from selenium import webdriver
DRIVER_PATH = 'chromedriver.exe'
link = 'https://upload.wikimedia.org/wikipedia/commons/7/75/NO_0301_Oslo.svg'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)
driver.get(link)
image = driver.page_source
#Creates an SVG File
f = open("kart/oslo.svg", "w")
f.write(image)
f.close()
driver.close()
Original artical that I get the file link from by running through the table in the article
关于如何提取此图像的任何想法,我知道 chrome 作为另存为的内置函数,我如何通过 selenium 访问它?
或者是否存在从 selenium 中保存 SVG 文件的工具?
在此先感谢您的帮助:D
它不是 selenium,但我让它在请求中工作,你不应该需要 selenium 来做这么简单的事情,除非你在它旁边做更多的事情:
import requests
def write_text(data: str, path: str):
with open(path, 'w') as file:
file.write(data)
url = 'https://upload.wikimedia.org/wikipedia/commons/7/75/NO_0301_Oslo.svg'
svg = requests.get(url).text
write_text(svg, './NO_0301_Oslo.svg')
目标: 从维基百科保存 SVG
要求: 需要自动化
目前我正在使用 selenium 获取一些其他信息,我尝试使用这样的 python 脚本来提取 svg 但提取的 SVG 文件渲染时出错。
编辑: 使用requests时出现同样的错误,可能与上传的文件wikipedia有关?
错误代码: Errorcode for svg file
稍后渲染部分svg: Rendered part of SVG
它应该是什么样子: Map;Oslo zoomed out
代码imageEctractSingle.py:
from selenium import webdriver
DRIVER_PATH = 'chromedriver.exe'
link = 'https://upload.wikimedia.org/wikipedia/commons/7/75/NO_0301_Oslo.svg'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)
driver.get(link)
image = driver.page_source
#Creates an SVG File
f = open("kart/oslo.svg", "w")
f.write(image)
f.close()
driver.close()
Original artical that I get the file link from by running through the table in the article
关于如何提取此图像的任何想法,我知道 chrome 作为另存为的内置函数,我如何通过 selenium 访问它?
或者是否存在从 selenium 中保存 SVG 文件的工具?
在此先感谢您的帮助:D
它不是 selenium,但我让它在请求中工作,你不应该需要 selenium 来做这么简单的事情,除非你在它旁边做更多的事情:
import requests
def write_text(data: str, path: str):
with open(path, 'w') as file:
file.write(data)
url = 'https://upload.wikimedia.org/wikipedia/commons/7/75/NO_0301_Oslo.svg'
svg = requests.get(url).text
write_text(svg, './NO_0301_Oslo.svg')