Re: [閒聊] 這個要怎麼parse...
貼出慘不忍睹的 code 來看一下了XD
# -*- coding: utf-8 -*-
import urllib, urllib2, cookielib, xml.dom.minidom
# origin 'eshopid': '996',
'eshoppwd': '711storemap',
'sid': '2',
'storecategory': '2',
'showtype': '1',
'storeid': ''
}
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode(data)
opener.open('http://emap.pcsc.com.tw/emap_switch.aspx', login_data)
#print cj._cookies
#print cj._cookies['emap.pcsc.com.tw']['/']['yearmonth'].value
#print cj._cookies['emap.pcsc.com.tw']['/']['ASP.NET_SessionId'].value
# area code
area_code = {
'台北市': '01',
'基隆市': '02',
'新北市': '03',
'桃園縣': '04',
'新竹市': '05',
'新竹縣': '06',
'苗栗縣': '07',
'台中市': '08',
#'台中縣': '09',
'彰化縣': '10',
'南投縣': '11',
'雲林縣': '12',
'嘉義市': '13',
'嘉義縣': '14',
'台南市': '15',
#'台南縣': '16',
'高雄市': '17',
#'高雄縣': '18',
'屏東縣': '19',
'宜蘭縣': '20',
'花蓮縣': '21',
'台東縣': '22',
'澎湖縣': '23',
'金門縣': '25',
'馬祖' : '24'
}
# function to get response
def get_resp(data):
post_data = urllib.urlencode(data)
resp = opener.open('http://emap.pcsc.com.tw/EMapSDK.aspx', post_data)
result = resp.read()
return result
# start req some data
# GET TOWM
for city in area_code:
data = {
'cityid': area_code[city],
'commandid': 'GetTown'
}
#print data
#post_data = urllib.urlencode(data)
#resp = opener.open('http://emap.pcsc.com.tw/EMapSDK.aspx', post_data)
#print city, xml.dom.minidom.parseString(resp.read())
#dom = xml.dom.minidom.parseString(resp.read())
dom = xml.dom.minidom.parseString(get_resp(data))
#dom = get_resp(data)
#print get_resp(data)
#xmldoc = dom.getElementsByTagName("iMapSDKOutput")
#print xmldoc
print '=====', city, '====='
#area = []
for node in dom.childNodes:
for node2 in node.getElementsByTagName("TownName"):
print ' ', node2.firstChild.nodeValue
#area.append(node2.firstChild.nodeValue)
data2 = {
'city': city,
'commandid': 'FindRoad',
'town': node2.firstChild.nodeValue
}
#print data2
#print data2
#post_data2 = urllib.urlencode(data2)
#resp2 = opener.open('http://emap.pcsc.com.tw/EMapSDK.aspx', post_data2)
print get_resp(data2)
#dom2 = xml.dom.minidom.parseString(resp2.read())
#print node2.firstChild.nodeValue, dom2
#print dom2.toxml()
#print "[", ", ".join(i for i in area), "]"
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.33.253.178
→
04/22 17:35, , 1F
04/22 17:35, 1F
→
04/22 17:54, , 2F
04/22 17:54, 2F
→
04/22 18:26, , 3F
04/22 18:26, 3F
→
04/22 18:28, , 4F
04/22 18:28, 4F
→
04/22 18:34, , 5F
04/22 18:34, 5F
→
04/22 20:36, , 6F
04/22 20:36, 6F
討論串 (同標題文章)
完整討論串 (本文為第 6 之 7 篇):
閒聊
2
10