使用Python去爬取全国的邮编号

#爬取全国的邮编import requestsfrom bs4 import BeautifulSoup#定义一个方法 来去指定省份的信息def get
#爬取全国的邮编
import requests
from bs4 import BeautifulSoup#定义一个方法 来去指定省份的信息
def  getYb(address):r = requests.get('http://www.ip138.com'+address)#转换编码解决中文问题t1 = r.text.encode('ISO-8859-1').decode('gbk')ht1 = BeautifulSoup(t1,'html5lib')#查询t12trs = ht1.select('table.t12')[0].select('tbody > tr')for j in trs[1:]:tds = j.select('td')if len(tds) > 1 and len(tds) < 5:print('    ',tds[0].text,tds[1].text,tds[2].text)if len(tds) > 4:print('    ',tds[0].text,tds[1].text,tds[2].text)print('    ',tds[3].text,tds[4].text,tds[5].text)#爬全国的地址 
resp =  requests.get('http://www.ip138.com/post/')
#转换编码解决中文问题
text = resp.text.encode('ISO-8859-1').decode('gbk')ht = Beau