I would like create an automatic script to download a .php textfile from a webpage which is frequently updated. My program uses requests to get the webpage.
The code:
import os, pathlib, subprocess,requests, time, sys url = 'http://metar.vatsim.net/metar.php?id=all' current_dir = pathlib.Path(__file__).parent os.chdir(current_dir) icao = sys.argv[1] fp = requests.get(url) mybytes = fp.read() mystr = mybytes.decode("utf8") fp.close() dict = {} fls = str.splitlines(mystr) for x in range(len(fls)): cur = str.split(fls[x]) dict[cur[0]] = " ".join(cur) try: print(dict[icao]) except: print('INCORRECT FORMAT OR AIRPORT ID\n')
When I try to read fp, it shows the err:
mybytes = fp.read() AttributeError: 'Response' object has no attribute 'read'
Is there a better way to solve this, I am kind of stuck.
https://stackoverflow.com/questions/67326926/how-can-i-get-frequently-updated-php-text-from-a-website-in-python-using-beauti April 30, 2021 at 09:06AM
没有评论:
发表评论