- 帖子
- 8
- 精华
- 0
- 积分
- 28
- 阅读权限
- 10
- 注册时间
- 2017-8-8
- 最后登录
- 2017-8-18
|
- #写入byte格式的内容,要用wb模式打开文件才行,w模式打开的文件不能正常写入
- #http://qq.ip138.com/weather/shanxi/taiyuan.htm 可查 但是好像没有山西省的天气。。。
- #北京地区。。。不能查全北京的天气,只能查具体的某个区,比如北京昌平
- import urllib.request
- url1 = 'http://qq.ip138.com/weather/'
- province = input('用拼音输入省份\n')
- city = input('用拼音输入城市\n')
- url = url1+province+'/'+city+'.htm'
- web = urllib.request.urlopen(url)
- content = web.read().decode('GB2312')
- #得用decode('GB2312')才能转换为恰当的格式
- data = content.split(',')
- need1 = data[10].split('var bds_config')
- need2 = need1[1].split(';')
- need3 = need2[0]
- need4 = need3[5:].split('。')
- need5 = need4[0]
- need6 = need5[9:].split('_')
- need7 = need6[1].split(';')
- need6[1] = need7
- print('\n',need6[0],':\n')
- for i in need6[1]:
- print(i,'\n')
复制代码 决定暂时先放弃抓取城市后写的提取天气的代码。感觉自己low爆了,虽然运行成功,但是全是list和str的运算,low。。。也秀下,毕竟是努力的结果。 |
|