栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 小红书处理记录(小程序)(二)根据笔记用户id获取用户信息

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 小红书处理记录(小程序)(二)根据笔记用户id获取用户信息

复制代码之前先看说明

代码说明:
1.最好先看前面 python 小红书处理记录(小程序)(一)获取关键词搜索出来的数据
2.获取用户信息这个会有风控,交给大家一个简单粗暴的方法:爬的时候,微信小程序自己也乱点点,看看这,看看那,爬的时候就会很顺畅

'''
Created on 2022年2月21日

@author: admin

'''
import hashlib
import requests
import warnings
import random
import pandas as pd
import time
warnings.filterwarnings("ignore")


bannerImage_list=[]
fans_list=[]
follows_list=[]
nickname_list=[]
notes_list=[]
def get_user(uid):
    
    url=f"https://www.xiaohongshu.com/fe_api/burdock/weixin/v2/user/{uid}"
    x_sign = 'X' + hashlib.md5(f"/fe_api/burdock/weixin/v2/user/{uid}WSUDD".encode(encoding='UTF-8')).hexdigest()
    headers={
        "Host": "www.xiaohongshu.com",
    "Connection": "keep-alive",
    "Authorization": "换成自己的",
    "Device-Fingerprint": "换成自己的",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat"
    ,"X-Sign": f"{x_sign}",
    "content-type": "application/json",
    "Referer": "https://servicewechat.com/wxb296433268a1c654/60/page-frame.html",
    "Accept-Encoding": "gzip, deflate, br"
    }

    #这里为了避免风控才整个随机获取headers,多整几个headers换着来爬更好
    headers_list=[headers1]
    res=requests.get(url=url,headers=random.choice(headers_list),verify=False)
    print(res.json())
    bannerImage_list.append(res.json()["data"]["bannerImage"])
    fans_list.append(str(res.json()["data"]["fans"]))
    follows_list.append(str(res.json()["data"]["follows"]))
    nickname_list.append(res.json()["data"]["nickname"])
    notes_list.append(res.json()["data"]["notes"])
dict_list={}  
erro_list=[]

data=pd.read_excel("五谷磨房黑芝麻丸笔记数据.xlsx")["笔记用户id"].to_list()
for key,value in enumerate(data):
    time.sleep(2)
    print(key)
    try:
        get_user(value)
    except:
        erro_list.append(value)
        pass


dict_list["头像"]=bannerImage_list
dict_list["粉丝数"]=fans_list
dict_list["关注人数"]=follows_list
dict_list["用户名"]=nickname_list
dict_list["发布笔记数"]=notes_list
 
data_=pd.Dataframe(dict_list)
data_.to_excel("五谷磨房黑芝麻丸用户信息.xlsx")
print(erro_list)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/744515.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号