result_notes

1. flex调用flash swc
放在UICOMPONENTS里面即可解决不能显示出来的问题
flash里面导出到actionscript能出类的定义?
from DrissionPage import ChromiumPage from urllib.parse import quote import pandas as pd import time import random from tqdm import tqdm def sign_in(): """登录小红书""" page = ChromiumPage() page.get('https://www.xiaohongshu.com') print("请扫码登录") time.sleep(20) def search(keyword): """搜索指定关键词""" global page page = ChromiumPage() page.get(f'https://www.xiaohongshu.com/search_result?keyword={keyword}&source=web_search_result_notes') def get_info(): """提取页面中的笔记信息""" global contents container = page.ele('.feeds-page') sections = container.eles('.note-item') for section in sections: try: note_link = section.ele('tag:a', timeout=0).link footer = section.ele('.footer', timeout=0) title = footer.ele('.title', timeout=0).text author_wrapper = footer.ele('.author-wrapper') author = author_wrapper.ele('.author').text author_link = author_wrapper.ele('tag:a', timeout=0).link author_img = author_wrapper.ele('tag:img', timeout=0).link like = footer.ele('.like-wrapper like-active').text contents.append([title, author, note_link, author_link, author_img, int(like)]) except Exception as e: print(f"信息提取错误: {e}") def page_scroll_down(): """向下滑动页面以加载更多数据""" print("********下滑页面********") random_time = random.uniform(0.5, 1.5) time.sleep(random_time) page.scroll.to_bottom() def craw(times): """循环下滑页面并获取数据""" for _ in tqdm(range(times)): get_info() page_scroll_down() def save_to_excel(data, filename="results.xlsx"): """保存数据到 Excel 文件""" name = ['title', 'author', 'note_link', 'author_link', 'author_img', 'like'] df = pd.DataFrame(columns=name, data=data) df['like'] = df['like'].astype(int) df = df.drop_duplicates() df = df.sort_values(by='like', ascending=False) df.to_excel(filename, index=False) print(f"数据已保存到 {filename}") if __name__ == '__main__': # 爬取存储容器 contents = [] # 搜索关键词 keyword = "外卖商战" times = 20 keyword_encode = quote(keyword) search(keyword_encode) craw(times) save_to_excel(contents) 在此基础上,爬取作者ID / 文章标题 / 文章内容 / 发布日期/ 发布地点 数量 / 收藏数量 / 评论数量 / 文章链接 / 文章类型,并存储为csv文件。尽量不要改变原本的代码
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值