The following script returns the current weather model from the url in the the script and works fine on my mac however I'm getting socket errors on pythonista3
from bs4 import BeautifulSoup as bs
import urllib
import re
import urllib2 as ul
import html5lib
base_url = 'https://weather.cod.edu/forecast/menus/gfs_menu.php?type=2018110518-AK-700-spd-0-0'
all_str = ''
def extract_names(filename, td):
text = re.findall(td,str(filename))
data_list = []
for line in text:
data_list.append(line)
return data_list
source = ul.urlopen(base_url).read()
tree = bs(source, 'html5lib')
filename = tree.find_all('td')
i = '\*'
td = re.compile(r'(\d+)Z' + i)
line_str = extract_names(filename, td)
line_str = str(line_str).strip('[]')
line_str = str(line_str).strip("'")
#all_str = all_str + line_str + '\n\n'
print line_str
I have used python 2.7 and tried python 3.6 with changing line 17 to :
source = urllib.request.urlopen(base_url).read()
I'm just starting on pythonista and trying to adapt some scripts that scrape weather sites for information that will be used to build custom url's to access the weather sites.
Any help is appreciated,
Thanks - Jerry