Skip to content

Instantly share code, notes, and snippets.

@n0531m
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0531m/e7c9ffb0607c26f3b448 to your computer and use it in GitHub Desktop.
Save n0531m/e7c9ffb0607c26f3b448 to your computer and use it in GitHub Desktop.
list ksj zip file urls
# http://nlftp.mlit.go.jp/ksj/api/about_api.html
# sudo port install py27-lxml
#sudo easy_install pip
#xcode-select --install
#sudo pip install lxml
import urllib2
from lxml import etree
def listKsjZipFileUrls():
url_summary="http://nlftp.mlit.go.jp/ksj/api/1.0b/index.php/app/getKSJSummary.xml?appId=ksjapibeta1&lang=J&dataformat=1"
#response=urllib2.urlopen(url_summary)
#xml=response.read()
#root=etree.fromstring(xml)
root=etree.parse(url_summary)
r=root.xpath("//item/identifier/text()");
#print len(r)
for identifier in r:
url="http://nlftp.mlit.go.jp/ksj/api/1.0b/index.php/app/getKSJURL.xml?appId=ksjapibeta1&dataformat=1&identifier="+identifier
datatree=etree.parse(url);
files=datatree.xpath("//item/zipFileUrl/text()");
for file in files:
print file
# print identifier
# print r
#return xml
listKsjZipFileUrls()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment