我是使用 python 2.7 的网络爬虫的新手。
一、背景
现在,我想收集有用的数据AQICN.org http://aqicn.org/city/shenyang/usconsulate/这是一个很棒的网站,提供世界各地的空气质量数据。
我想用python获取中国所有网站每小时的数据。但我现在被困住了。
2.我的烦恼
拿这个网站(http://aqicn.org/city/shenyang/usconsulate/ http://aqicn.org/city/shenyang/usconsulate/) 例如。
本页提供美国驻华领事馆的空气污染和气象参数。使用这样的代码,我无法获得有用的信息。
import urllib
from bs4 import BeautifulSoup
import re
import json
html_aqi =
urllib.urlopen("http://aqicn.org/city/shenyang/usconsulate/json").read().decode('utf-8')
soup= BeautifulSoup(html_aqi)
l = soup.p.get_text()
aqi= json.loads(l)
结果显示如下:
> ValueError: No JSON object could be decoded
所以,我将 html_aqi 更改为这种格式(参考某人的工作):
http://aqicn.org/aqicn/json/android/shenyang/usconsulate/json http://aqicn.org/aqicn/json/android/shenyang/usconsulate/json
该代码运行良好。
3.我的目标。
格式1:(http://aqicn.org/city/shenyang/usconsulate/json) http://aqicn.org/city/shenyang/usconsulate/json)_