我已经成功爬虫并且得到json文件,print(response.text)之后,输出了完整的数据,但是我只想输出item-name和item-type,print后面应该怎么写啊?
多了一个括号
print()前面加一层级缩进,放到for语句块内
可以参考以下下面这个代码哦,这种就是获取json数据的写法,不难理解的
#json数据链接
json_url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false'
response = requests.post(json_url,data=data,headers=headers,cookies=cookies)
# print(response.text)
contents = json.loads(response.text)['content']['positionResult']['result']#json反序列化
#提取数据
for content in contents:
positionId = content['positionId']#职位id
positionName = content['positionName']#职位名字
companyFullName = content['companyFullName']#公司全称
companySize = content['companySize']#公司规模
city = content['city']#城市
salary = content['salary']#薪资
education = content['education']#学历
workYear = content['workYear']#工作经验
skillLables = content['skillLables']#技能要求(是一个列表数据)
skillLables = ' '.join(skillLables)#将列表转成字符串
createTime = content['createTime']#发布时间
data = [positionName, companyFullName, companySize, city, salary, education, workYear, skillLables, createTime]
print(positionName, companyFullName, companySize, city, salary, education, workYear, skillLables, createTime)
get_detail_information(positionId,data)
for i in l_items:
print(i['item_name'],i['item_type'])
不用.text,用.json()可以获取python格式的字典,再根据字典的操作方法来操作
import json
import requests
res = requests.get("https://pvp.qq.com/web201605/js/item.json")
items = json.loads(res.text)
for item in items:
print(item['item_name'], item['item_type'])