Skip to content

Instantly share code, notes, and snippets.

@hondajojo
Created May 19, 2015 07:47
Show Gist options
  • Save hondajojo/3e606ec8dff479656523 to your computer and use it in GitHub Desktop.
Save hondajojo/3e606ec8dff479656523 to your computer and use it in GitHub Desktop.
法院链接
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from pyquery import PyQuery as pq
class Rmfy(object):
def __init__(self):
self.origin_url = 'http://www.rmfysszc.gov.cn/'
self.province_url = {}
self.city_url = {}
self.town_url = {}
def get_province(self):
res1 = requests.get(self.origin_url).content
pq_content = pq(res1)('.divbody_r1_r1_c1_r1_c1_r3 > a')
for i in pq_content.items():
self.province_url[i.text()] = i.attr.href
return self.province_url
def get_city(self):
url = [value for key,value in self.get_province().items()]
for i in url:
res2 = requests.get(i).content
for i in pq(res2)('.r2_r4_r2_r1_div > a').items():
self.city_url[i.attr.title] = i.attr.href
return self.city_url
def get_town(self):
url = [value for key,value in self.get_city().items()]
for i in url:
res3 = requests.get(i).content
for i in pq(res3)('.r2_r4_r2_r1_div > a').items():
self.town_url[i.attr.title] = i.attr.href
return self.town_url
a = Rmfy().get_province() #省 dict
b = Rmfy().get_city() #市 dict
c = Rmfy().get_town() #县 dict
for x,y in a.items():
print x,y
for x,y in b.items():
print x,y
for x,y in c.items():
print x,y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment