정확하게 이해했다면 위에 쓴 줄이있는 HTML 파일이 있습니다. (LAT, LONG) 부분을 파이썬 스크립트에서 찾을 실제 lat 및 long 값으로 대체하려고합니다.
맞습니다 경우, 나는 앞서가는이 .txt 파일에 HTML 파일을 작성하는 것이 좋습니다 :이 코드를 테스트하지 않았습니다
import urllib
import time
while True:
open = urllib.urlopen(the_url_where_the_html_comes_from)
html = open.read()
my_file = open("file.txt","w")
my_file.write(html)
my_file.close()
#you don't need any fancy modules or RegEx to edit one unique line.
my_file = open("file.txt","r+")
text = my_file.read()
text.replace("LatLng(LAT,LONG)","LatLng("+lat_variable+","+long_variable+")")
real_text = text
my_file.close()
#now you want the change that you made to remain in that file
my_file = open("file.txt","w")
my_file.write(real_text)
my_file.close()
#if you check "file.txt", it should have those values replaced.
time.sleep(However long until the html updates)
를, 그래서 작동 여부를 알려 주시기!
편집 : HTML 파일이 계속 변경되는 경우 urllib 모듈을 사용하여 HTML 파일을 업데이트 할 수 있습니다. 위의 코드를 참조하십시오.
이 프로그램은 HTML 파일을 생성합니까
감사 : 나는 다음을 사용하여 문제를 해결? 그렇지 않다면 [HTML 구문 분석기] (https://docs.python.org/3/library/html.parser.html) 또는 [XML 구문 분석기] (https://docs.python.org/ 2/library/xml.dom.minidom.html). – Seth
[파이썬에서 파일의 라인 검색 및 바꾸기] 가능한 중복 (http://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python) – kojiro
나는 그들이 똑같은 질문처럼 보이지 않을지도 모른다는 것을 안다. 그러나 나는 궁극적으로 그것들이 있다고 생각하며,이 문제에 대해 가장 많이 상심 받았다. – kojiro