python小白 调试程序 遇到报错
from urllib import request, parse
这句话报错
AttributeError: 'module' object has no attribute 'urllopen'
参考http://blog.csdn.net/aug0st/article/details/42707709
好的 我看看 谢谢
这个跟from urllib import request, parse没有关系,是用到urllopen的那行代码有错,多粘贴一点代码出来
def SearchPageCount(position, city):
url = 'http://www.lagou.com/jobs/positionAjax.json?'
params = {'city': city, 'kd': position}
url += parse.urlencode(params)
with request.urlopen(url) as f:
data = f.read()
content = json.loads(str(data, encoding='utf-8', errors='ignore'))['content']
count = int(content['totalPageCount'])
totalCount = int(content['totalCount'])
print('本次搜索到'.format(totalCount))
return count
def get_rdata(url):
data = request.urlopen(url).read()
params = parse.parse_qs(parse.urlparse(url).query)
print('正在解析第{0}页...'.format(params.get('pn', [''])[0]))
# 读取Json数据
jsondata = json.loads(str(data, encoding='utf-8', errors='ignore'))['content']['result']
for t in list(range(len(jsondata))):
jsondata[t]['companyLabelListTotal'] = '-'.join(jsondata[t]['companyLabelList'])
jsondata[t].pop('companyLabelList')
这个么
@elivs:
from urllib import request, parse def SearchPageCount(position, city): url = 'http://www.lagou.com/jobs/positionAjax.json?' params = {'city': city, 'kd': position} url += parse.urlencode(params) with request.urlopen(url) as f: data = f.read() content = json.loads(str(data, encoding='utf-8', errors='ignore'))['content'] count = int(content['totalPageCount']) totalCount = int(content['totalCount']) print('本次搜索到{0}'.format(totalCount)) return count def get_rdata(url): data = request.urlopen(url).read() params = parse.parse_qs(parse.urlparse(url).query) print('正在解析第{0}页...'.format(params.get('pn', [''])[0])) # 读取Json数据 jsondata = json.loads(str(data, encoding='utf-8', errors='ignore'))['content']['result'] for t in list(range(len(jsondata))): jsondata[t]['companyLabelListTotal'] = '-'.join( jsondata[t]['companyLabelList']) jsondata[t].pop('companyLabelList')
执行代码没有报错AttributeError: 'module' object has no attribute 'urllopen'