如何从互联网网址获取文本? [关闭]

问题描述 投票:-3回答:1
我需要从用手机创建的URL获取文本(本地化)。我可以使其与Python 3一起使用,但需要与Python 2.7一起使用。

为什么会出现此错误?我只需要获取一个包含URL和操作中的数字的变量(转到)。

import urllib2 import urllib import requests req = urllib2.Request('https://dev1.icam.fr/~GPS-TRACKER/mouchel.txt') response = urllib2.urlopen(req) a = response.read print (a)

对于python 3(有效):

import urllib.request url = "https://dev1.icam.fr/~GPS-TRACKER/mouchel.txt" request = urllib.request.Request(url) response = urllib.request.urlopen(request) print (response.read())

Traceback (most recent call last):
  File "C:\Users\Simon\Downloads\dronePA-20200402T121323Z-001\dronePA\src\F3.py", line 7, in <module>
    response = urllib2.urlopen(req)
  File "C:\Python27\lib\urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 429, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 447, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1241, in https_open
    context=self._context)
  File "C:\Python27\lib\urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)>
我如何修复

import urllib2 import urllib import requests import ssl req = urllib2.Request('https://dev1.icam.fr/~GPS-TRACKER/mouchel.txt') context = ssl._create_unverified_context() response = urllib2.urlopen('https://dev1.icam.fr/~GPS-TRACKER/mouchel.txt', context=context).read() print (response)

现在我得到回应:

48.03113 0.25918 Go

如何创建包含此变量的3个变量?我需要一个变量包含48.03113,另一个变量包含0.25918,另一个变量“转到”。

My URL site from which I need to get the text

python python-2.7 url
1个回答
0
投票
尝试一下并告知答案:

import urllib2 r = urllib2.urlopen('PASTE YOUR URL HERE') print(r.read())

© www.soinside.com 2019 - 2024. All rights reserved.