現在是使用python和json一個一個網頁下載資料,如何beautifulsoup抓取一個網址自動更新得到全部資料?
//網頁網址:http://data.gov.tw/node/28691?page=1
import json
import pickle
import requests
from pprint import pprint
from bs4 import BeautifulSoup
---高雄市
g2 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E9%AB%98%E9%9B%84&classify=%E9%AB%98%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(g2.text)
print('高雄市-高潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
g1 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E9%AB%98%E9%9B%84&classify=%E4%B8%AD%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(g1.text)
print('高雄市-中潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
g0 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E9%AB%98%E9%9B%84&classify=%E4%BD%8E%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(g0.text)
print('高雄市-低潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
---臺南市
h2 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E8%87%BA%E5%8D%97&classify=%E9%AB%98%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(h2.text)
print('臺南市-高潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
h1 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E8%87%BA%E5%8D%97&classify=%E4%B8%AD%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(h1.text)
print('臺南市-中潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
h0 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E8%87%BA%E5%8D%97&classify=%E4%BD%8E%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(h0.text)
print('臺南市-低潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
---新竹縣及新竹市
i2 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E6%96%B0%E7%AB%B9&classify=%E9%AB%98%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(i2.text)
print('新竹縣及新竹市-高潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
i1 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E6%96%B0%E7%AB%B9&classify=%E4%B8%AD%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(i1.text)
print('新竹縣及新竹市-中潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
i0 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E6%96%B0%E7%AB%B9&classify=%E4%BD%8E%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(i0.text)
print('新竹縣及新竹市-低潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
-臺北盆地(臺北市及新北市)
j2 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E8%87%BA%E5%8C%97&classify=%E9%AB%98%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(j2.text)
print('臺北盆地(臺北市及新北市)-高潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
j1 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E8%87%BA%E5%8C%97&classify=%E4%B8%AD%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(j1.text)
print('臺北盆地(臺北市及新北市)-中潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])
j0 = requests.get('http://www.geologycloud.tw/data/zh-tw/liquefaction?area=%E8%87%BA%E5%8C%97&classify=%E4%BD%8E%E6%BD%9B%E5%8B%A2&all=true')
doc = json.loads(j0.text)
print('臺北盆地(臺北市及新北市)-低潛勢')
for x in doc['features']:
print(x['geometry']['coordinates'])