나는이 txt 파일에 URL을 마지막에서 두 번째 열에서 자리를 얻기 위해 노력하고 있어요.Python을 사용하여 원격 텍스트 파일에서 마지막 문자를 검색하는 방법은 무엇입니까? <a href="http://services.swpc.noaa.gov/text/wing-kp.txt" rel="nofollow noreferrer">http://services.swpc.noaa.gov/text/wing-kp.txt</a></p> <p>가 난 단지 파일의 맨 끝에 두 번째 마지막 열의 마지막 값이 필요합니다
내가 파이썬 3에서 몇 가지 샘플 코드를 시도
이 코드는 나에게 파일의 시작 부분에서 시작하여 문자의 특정 량의 수 (0.4?) :
# coding: utf-8
import urllib.request
req = urllib.request.Request('http://services.swpc.noaa.gov/text/wing-kp.txt')
with urllib.request.urlopen(req) as response:
the_page = response.read(100)
print (the_page)
을 .seek 함수를 시도했지만 인식 할 수없는 값을 반환했습니다.
다음 코드에서는 웹 페이지에서 직접 .seek를 사용하려고 시도했지만 작동하지 않아 먼저 파일을 저장하고 성공/제한 성공없이 파일에서 읽으려고했습니다. 만 두 번째 마지막 값이 필요한 경우
# coding: utf-8
import urllib.request
req = urllib.request.Request('http://services.swpc.noaa.gov/text/wing-kp.txt')
with urllib.request.urlopen(req) as response:
open('data.txt', 'wb').write(urllib.request.urlopen(req).read())
file = open('data.txt' , 'rb+')
data = file.seek(-5, 2)
file.close()
print (data)
답변 해 주셔서 감사합니다. 그것은 내가 찾던 바로 그 것이다. –