import requests
import random
import json
import csv
import time
now_time = int(time.time())
timeStamp = now_time*1000
for a in range(3):
url = 'https://www.igoyun.cn/igo-cloud-bizdiscovery/espurbid/fineespurbid?&pageNo={}&pageSize=24¬icestate=2'.format(a)
headers = {
"User-Agent":'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'
response = requests.get(url = url.format(timeStamp),headers = headers)
content = response.content.decode('utf-8')
content_dict = json.loads(content)
post_list = content_dict['result']['content']
time.sleep(random.randrange(1,3))
print(a)
for value_dict in post_list:
pubcomname = value_dict['pubcomname']
noticetype = value_dict['noticetype']
if noticetype=='1' :
newNoticetype='询价公告'
elif noticetype=='2' :
newNoticetype='采购/招标公告'
elif noticetype=='4' :
newNoticetype='竞价公告'
elif noticetype=='5' :
newNoticetype='中标公示'
elif noticetype=='6' :
newNoticetype='竞争性谈判'
else :
newNoticetype=noticetype
catalogname = value_dict['catalogname']
noticetitle = value_dict['noticetitle']
pubtime = value_dict['pubtime'][0:10]
exptime = value_dict['exptime'][0:10]
in_fo_list =[pubcomname,newNoticetype,catalogname,noticetitle,pubtime,exptime]
with open('E:/langchao.csv','a',newline = '',encoding='utf-8-sig') as f:
writer = csv.writer(f)
writer.writerow(in_fo_list)
根据路径打开文件:
爬取成功!
# "rating": ["9.2", "45"],
# "rank": "21",
# "cover_url": "https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p51114
CSV文件简介
CSV(Comma-Separated Values,逗号分隔值),是一种纯文本形式存储表格数据的文件。该文件由任意数目的记录组成,每条记录被分隔符分隔为字段(最常见的分隔符是逗号或制表符),且每条记录都有相同的字段序列,因此csv相当于一个结构化表的纯文本形式。从直观上看,它比Excel文件更加简洁,然而它不包含诸如XLS电子表格的数值、公式和格式等内容,它仅仅为一个结构化的纯...
import jsonimport csvjson_str = '[{"a":1,"b":"2","c":"3","d":{"d1":"4"}},{"a":21,"c":"23","d":{"d1":"24"},"e":"25"}]'o = json.loads(json_str)def loop_data(o, k=''):global json_ob, c_lineif isinstance(...
# coding=utf-8import jsonimport csv# 重新进行配置读写数据时的默认编码import sysreload(sys)sys.setdefaultencoding('utf-8')def json_to_csv():# 1.读取json文件的数据json_file = open('5Tencent.json', 'r')# 2. csv的写入文件对象csv_file ...
文章目录了解json整体格式转换格式提取key和value使用pandas写入csv
了解json整体格式
这里有一段json格式的文件,存着全球陆地和海洋的每年异常气温(这里只选了一部分):global_temperature.json
"description": {
"title": "Global Land and Ocean Temperature Anomalies, January-December",
"units": "Degrees Celsius",