作者unhumanWu (阿文)
看板Python
標題[問題] 爬蟲資料格式及處理
時間Wed Oct 25 22:12:28 2017
大家好,初學爬蟲
透過以下程式抓到文字資料
https://imgur.com/mGAOY9I
https://imgur.com/GwWX8f3
想問一下這是哪種資料類型阿?
有像html之於BeautifulSoup的library可以處理嗎?
感恩!
import requests
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)'
headers = {'User-Agent': user_agent,
'Referer':'
http://www.family.com.tw/marketing/inquiry.aspx'}
response = requests.get("
http://api.map.com.tw/net/familyS"
"hop.aspx?searchType=ShopList&type="
"&city=%E5%9F%BA%E9%9A%86%E5%B8%82"
"&area=%E4%BB%81%E6%84%9B%E5%8D%80&"
"road=&fun=showStoreList&key=6F30E8"
"BF706D653965BDE302661D1241F8BE9EBC"
, headers=headers)
response.text
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.136.49.4
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1508940751.A.DCD.html
1F:→ stucode: 看起來是 JSON,Python 有內建函數庫。 10/25 22:23
2F:推 ssdoz2sk: 你把前面的 showStoreList( 去掉,還有最後的 ) 去掉, 10/25 22:23
3F:→ ssdoz2sk: 就可以用 json.loads 讀取 JSON 10/25 22:25
4F:推 ckc1ark: JSONP 用來繞過same origin policy的 10/25 22:27
5F:→ vi000246: 你網址裡面有一串key參數 這應該是csrf token吧 10/26 00:39
6F:→ vi000246: get的時候要記得更新這個key 10/26 00:40
7F:→ vi000246: 還有個fun參數 應該是用來決定回傳的資料格式 10/26 00:41
8F:→ vi000246: 你可以研究一下怎麼讓他直接傳回json 10/26 00:41
9F:推 rexyeah: eval(response.text.strip()) probably get a dict 10/26 08:41
10F:→ rexyeah: 樓上說的沒錯 要把showStoreList去掉才eval得出東西 10/26 08:49
11F:推 TitanEric: JSON 10/26 15:13
把showStoreList去掉就可順利讀取,感恩!
fun的部分有storeTownList和showStoreList
一個列出有店點的行政區;一個是店點資料
key的部分目前看似乎都長一樣
https://imgur.com/DVCqwNu
https://imgur.com/3Tar5R8
※ 編輯: unhumanWu (220.136.49.4), 10/26/2017 20:43:07