#!/usr/bin/env python # -*- coding:utf-8 -*- import urllib.request#这里必须要加request import urllib.parse import requests import sys #sys.Setdefaultencoding('utf-8') import urllib import json import time from bs4 import BeautifulSoup #发起GET请求 # url = 'http://kaoshi.edu.sina.com.cn/college/scorelist?tab=batch&wl=1&local=2&batch=&syear=2013' # response = urllib.request.urlopen(url=url) # result = response.read().decode('utf-8')#解码后可以正常输出 # print(result) #发起POST请求 url = "http://shuju.wdzj.com/plat-info-59.html" data = urllib.parse.urlencode({'type1':'x','type2':0,'status':0}).encode('utf-8') request = urllib.request.Request(url=url,data=data) #opener = urllib.build_open(urllib.HTTPCookieProcessor()) #跟上述差不多,只是了一个data response = urllib.request.urlopen(request) result = response.read().decode('utf-8') print(result) result = result.replace('<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">', '') result = result.replace('</pre></body></html>', '') for key in json.loads(result,strict=False).keys(): print(key) #报错:json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)