爬下artstation关注的画师信息制作为json文件

原始网站 https://www.artstation.com/
Author:xiaozhu_sai
本文章仅供学习交流,请勿交流梯子以及版权问题

1、爬取数据目的&后续处理

  • 方便后续对各个画师作品的个人下载
  • 个人练习‘用户关注’的推荐算法与其大数据

处理后数据:在这里插入图片描述

2、使用who-you-konw提供的端口位置以及加载时候的访问API即可获取所有画师的json信息https://www.artstation.com/users/个人ID/following.json?page=1

一个page有20个画师,在遍历的时候注意这一点就行了
在这里插入图片描述
在这里插入图片描述

3、json文件的写入与读取

没啥可说的,代码如下
注意如果是使用的vscode读取json信息,不要看调试控制台终端的数据,因为会显示不全,一定要保存到Json确定。(使用res.text/ content或者res.json()数据相同)

# 写入
        os.makedirs('JSON', exist_ok=True)
        with  open(os.path.join('JSON/ArtstationPage-'+str(i)+'.json'), 'w+') as items:
            json.dump(s, items, sort_keys=True,  indent=4)
## 读取
        with open(os.path.join('JSON/artstation-page-'+str(i)+'.json'), 'r') as items:
            data_json = json.load(items)['data']

4、画师信息

artstation的每个画师信息相当的完善(部分如图),我只需要id 域名 画师名 国家 简介等这几个基本信息即可
注意username和subdomin域名是一样的
在这里插入图片描述

5、画师信息保存(写入)

步骤

  • 遍历所有的page,将各类数据分别按顺序存储在List中
  • 画师信息为Dict对象,简介 技能等多个数据采用List存储(见首图)
  • 简介使用re.split()分割,保留邮箱,后续会优化“中文”
  • 因为个人关注画师会不断增加,以及保存了followers,会保存一个脚本运行时间"time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
  • 在这里插入图片描述

domain = []
full_name = []
id = []
followers_count = []
location = []
skills = []
software = []
headline = []

try: 
    for i in range(1,43):
        with open(os.path.join('JSON/followingPage/ArtstationPage-'+str(i)+'.json'), 'r') as items:
            #data_json是一个list有20个dict,'id, subdomain/suername, followers_count, full_name
            data_json = json.load(items)['data']
            
            for j in range(len(data_json)):
                domain.append((data_json[j]['subdomain']))
                full_name.append(data_json[j]['full_name'])
                id.append(data_json[j]['id'])
                followers_count.append(data_json[j]['followers_count'])
                location.append(data_json[j]['location'])
                skills.append([i['name'] for i in data_json[j]['skills']])
                software.append([i['name'] for i in data_json[j]['software_items']])
                headline.append(re.split('[^(\w | @ | \. | \|)]+', data_json[j]['headline']))
           
    artists_json = {
        "time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
        "data":[
            {}
        ]
    }
    for i in range(len(id)):
        temp_json = {
            "id":id[i],
            "full_name":full_name[i],
            "subdomain_and_username":domain[i],
            "headline":headline[i],
            "url":"https://www.artstation.com/" + domain[i],
            "location":location[i],
            "skills":skills[i],
            "software":software[i],
            "followers_count":followers_count[i],
        }
        artists_json['data'].append(temp_json)

    # 写入
    os.makedirs('JSON', exist_ok=True)
    with  open(os.path.join('JSON/ArtstationArtists.json'), 'w+') as items:
        json.dump(artists_json, items, indent=4)
    print('正常写入')

except Exception as e:
    print(e)

6、后续处理以及优化

  • 进行数据可视化,并且训练推荐算法
  • 将画师作品更新至本地/ Eagle,已确定每张作品存在唯一‘ID’
  • 未来优化:增加多线程携程爬取(因工作量不大,目前为单线程),python版本制作为库,使用接口即可。更新Js油猴插件版本。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值