免责声明:本文仅做分享!!!
from DrissionPage import ChromiumPage
import time
pa = str(input("输入关键词:"))
pl = str(input("输入评论内容:"))
page = ChromiumPage()
page.get('https://www.xiaohongshu.com/search_result?keyword=' + pa + '&source=unknown&type=51')
print("网站加载成功!")
time.sleep(2)
for time_button in range(1, 20): # 下滑多少下 你就改多少下
time.sleep(2)
page.scroll.to_bottom()
print("当前下滑:", time_button, "次,剩余", 20 - time_button, "次后,将会开始抓取数据...")
print("全部下滑完毕开始抓取页面的元素链接!")
my_list = list()
ele = page.eles('.cover ld mask')
name_ele = page.eles('.title')
for href,name in zip(ele,name_ele):
lian = href.link
na = name.text
print(na,lian)
my_list.extend(lian.split(','))
print("元素链接抓取完毕 已存入列表my_list")
sums = 0
print("本次获取数据:", len(my_list),"条")
for like_list in my_list:
sums = sums + 1
print("序号:", sums, "链接:", like_list)
page.get(like_list)
time.sleep(1)
input_list1 = page.ele('.chat-wrapper').click()
input_list2 = page.ele('.content-input').input(pl)
time.sleep(0.5)
button = page.ele('.btn submit').click()
print("发送成功:",pl,"-")
time.sleep(2)
print("*"*30)
input("==结束==")