无法检测"urltest"错误的URI方案 Python
我在用Python从一个.txt文件读取数据时,尝试打开一个网址,结果出现了错误,这个网址是我通过match.group()获取的。下面是我出错的代码。如果有人能帮我解决这个问题,我会非常感激。
with open('output.txt') as f:
for line in f:
match = re.search("(?P<url>https?://docs.google.com/file[^\s]+)", line)
if match is not None:
urltest = match.group()
print urltest
print "[*] Opening Map in the web browser..."
kml_url = "urltest"
try:
webbrowser.get().open_new_tab(kml_url)
1 个回答
0
因为你没有提供你想要解析的内容,所以我只能猜测,但这个代码应该可以适用于你的网址:
>>> import re
>>> match = re.search('(?P<url>https:\/\/docs.google.com\/file[a-zA-z0-9-]*)', 'https://docs.google.com/fileCharWithnumbers123')
>>> match.group("url")
'https://docs.google.com/fileCharWithnumbers123'