2021-10-28_tiktok红人视频爬虫-程序员宅基地

技术标签: python  笔记  

Tiktok爬虫

github地址:https://github.com/carcabot/tiktok-signature.git,亲测有效

Installation

npm i tiktok-signature

Buy Me A Coffee

Usage

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s0WNkkl8-1635413604581)(examples/howto.gif)]

Generating signatures on high performance level

Build
docker build . -t tiktok-signature
Run
docker run -p 80:8080 -v $(pwd):/usr/app tiktok-signature

Example

Request signature
curl -X POST \
     -H "Content-type: application/json" \
     -d 'https://m.tiktok.com/share/item/list?secUid=&id=&type=5&count=30&minCursor=0&maxCursor=0&shareUid=' \
     http://localhost/signature

To generate signatures dynamically this repo comes with an integrated http server (listen.js) which accepts POST requests to http://localhost/signature with url in request body.

You have to start the server

npm start

Module

const Signer = require("tiktok-signature"); // Import package

const signer = new Signer(); // Create new signer
await signer.init(); // Create page with. Returns promise

const signature = await signer.sign("tiktok url"); // Get sign for your url. Returns promise
const navigator = await signer.navigator(); // Retrieve navigator data used when signature was generated

console.log(signature);
console.log(navigator);

await signer.close(); // Close browser. Returns promise

You can pass your desired User-Agent on class creation.

new Signer("Mozilla"); // Set User-Agent to Mozilla

CLI

Install dependencies

npm i playwright-chromium

Now you can generate the token using

node browser.js "https://m.tiktok.com/api/post/item_list/?aid=1988&count=30&secUid=MS4wLjABAAAAOUoQXeHglWcq4ca3MwlckxqAe-RIKQ1zlH9NkQkbLAT_h1_6SDc4zyPdAcVdTWZF&cursor=0"

The response token should look like this

{
    
  "status": "ok",
  "data": {
    
    "signature": "_02B4Z6wo00f01DBbvBwAAIBCcuSZt1Pua8AwS7iAAGyZ6e",
    "verify_fp": "verify_knvz9j2k_miXwiqOy_msam_42g2_BYoa_e4EAbuQnDwqI",
    "signed_url": "https://m.tiktok.com/api/post/item_list/?aid=1988&count=30&secUid=MS4wLjABAAAAOUoQXeHglWcq4ca3MwlckxqAe-RIKQ1zlH9NkQkbLAT_h1_6SDc4zyPdAcVdTWZF&cursor=0&verifyFp=verify_knvz9j2k_miXwiqOy_msam_42g2_BYoa_e4EAbuQnDwqI&_signature=_02B4Z6wo00f01DBbvBwAAIBCcuSZt1Pua8AwS7iAAGyZ6e",
    "x-tt-params": "1BLhm+0j/AG2Dlsz3v4u4w==",
    "navigator": {
    
      "width": 884,
      "height": 1244,
      "deviceScaleFactor": 3,
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Windows NT 10.0; Win64; x64) Chrome/90.0.4430.85 Safari/537.36",
      "browser_language": "en-US",
      "browser_platform": "MacIntel",
      "browser_name": "Mozilla",
      "browser_version": "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Windows NT 10.0; Win64; x64) Chrome/90.0.4430.85 Safari/537.36"
    }
  }
}

Testing

You can test it using trending.py file included in this repo.

pip install Naked
python examples/trending.py

NOTE

It’s very important that the userAgent be the same when generate and when request for response.

Keeping a process too much time opened can increase memory usage, to avoid this uncomment the following lines in listen.js.

// setTimeout(function () {
    
//   server.close(() => {
    
//     console.log("Server shutdown completed.");
//     process.exit(1);
//   });
// }, 1 * 60 * 60 * 1000);

Buy Me A Coffee

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/carcabot/tiktok-signature.

  1. Fork it (https://github.com/carcabot/tiktok-signature/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some new feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The lib is available as open source under the terms of the MIT License.

需要注意的地方
1.测centons系统启动安装playwright,缺少依赖,建议使用docker启动。
2.需要用境外代理,香港的代理不行,配置代理在index.js中修改,在这里插入图片描述3,docker启动.需要进入docker修改镜像
docker 启动后
docker ps #查看容器id
docker exec -it 容器id bash #进入容器
使用vim命令修改index.js文件,增加代理配置,提示没有vim命令,使用apt-get vim 安装

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_45608952/article/details/121019407

智能推荐

android:layout_weight="1",Android:LinearLayout布局中Layout_weight的深刻理解-程序员宅基地

文章浏览阅读2.9k次,点赞2次,收藏3次。首先看一下LinearLayout布局中Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重。很多人不知道剩余空间是个什么概念,下面我先来说说剩余空间。看下面代码:android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_par..._"android:layout_weight=\"1"

jenkins war包_Jenkins在Java web项目CI/CD中的简单应用-程序员宅基地

文章浏览阅读94次。JenkinsJenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.主要介绍使用Jenkins..._jenkins构建javaweb应用指定war包名

课节6: 图神经网络进阶模型之 ERNIESage 上-程序员宅基地

文章浏览阅读779次。ERNIESage是用在NLP的一个模型。UniMP是标签传播的一个模型https://aistudio.baidu.com/aistudio/education/lessonvideo/937035ERNIESageERNIE结构其实就是多层的transformer。_erniesage

微信小程序入门教程 --(保姆级)-程序员宅基地

文章浏览阅读6.7k次,点赞24次,收藏92次。小程序入门保姆级教程_微信小程序入门

计算机毕设 深度学习猫狗分类 - python opencv cnn_毕业设计可以用猫狗大战吗-程序员宅基地

文章浏览阅读559次。 这两年开始毕业设计和毕业答辩的要求和难度不断提升,传统的毕设题目缺少创新和亮点,往往达不到毕业答辩的要求,这两年不断有学弟学妹告诉学长自己做的项目系统达不到老师的要求。为了大家能够顺利以及最少的精力通过毕设,学长分享优质毕业设计项目,今天要分享的是 **基于深度学习猫狗分类 **学长这里给一个题目综合评分(每项满分5分)难度系数:3分工作量:3分创新点:3分。_毕业设计可以用猫狗大战吗

手把手教你安装Eclipse最新版本的详细教程 (非常详细,非常实用)_eclipse安装教程-程序员宅基地

文章浏览阅读4.4k次,点赞2次,收藏16次。写这篇文章的由来是因为后边要用这个工具,但是由于某些原因有部分小伙伴和童鞋们可能不会安装此工具,为了方便小伙伴们和童鞋们的后续学习和不打击他们的积极性,因为80%的人都是死在工具的安装这第一道门槛上,这门槛说高也不高说低也不是太低。所以就抽时间水了这一篇文章。_eclipse安装教程

随便推点

OnTriggerEnter事件、以及触发碰撞、刚体碰撞研究尝试-程序员宅基地

文章浏览阅读6.9k次,点赞4次,收藏7次。一、触发碰撞和刚体碰撞共性:碰撞双方都需要加碰撞器组件,至少有一个添加了刚体组件rigidbody;异同:触发碰撞需要在 碰撞器勾选is trigger选项,刚体碰撞需要使用物理动力模式(isKinematic 选项不能勾选)二、OnTriggerEnter事件执行特点;OnTriggerEnter事件不是每帧调用的,它是基于RigidBody物理碰撞后调用的,不管事件所在的脚本是..._ontriggerenter

腾讯云服务器网站搭建教程(太简单了)_腾讯云建站-程序员宅基地

文章浏览阅读5.6k次,点赞8次,收藏62次。已经有了腾讯云服务器如何搭建网站?腾讯云服务器网以腾讯云服务器,借助宝塔面板搭建Web环境,然后使用WordPress博客程序搭建网站,大致分为三步,首先购买腾讯云服务器,然后在腾讯云服务器上部署宝塔面板,最后在宝塔面板上安装WordPress程序。_腾讯云建站

WebSphere MQ6.0 for redhat4.6 setup_websphere mq6.0下载-程序员宅基地

文章浏览阅读956次。WebSphere MQ6.0 for redhat4.6 setup分类: WebSphere 2010-04-12 14:45650人阅读 评论(0)收藏举报websphereredhatmanageribm消息中间件statisticsWebsphere MQ是IBM的商业消息中间件(Commercial Messaging Middlewar_websphere mq6.0下载

Spring——Bean 的生命周期_spring bean的生命周期-程序员宅基地

文章浏览阅读1.1w次,点赞11次,收藏49次。目录一、Bean 的生命周期二、代码演示三、主要步骤简述一、Bean 的生命周期  对于普通的 Java 对象,new 的时候会去创建对象,而当它没有任何引用的时候则被垃圾回收机制回收。相较于前者,由Spring IoC 容器托管的对象,它们的生命周期完全由容器控制。Spring 中每个 Bean 的生命周期如下:对于 ApplicationContext 容器,当容器启动结束后,实例化所有的 Bean。设置对象属性,即依赖注入,动态将依赖关系注入到对象中。紧接着,Spring 会检测该对象_spring bean的生命周期

matlab_matlab fat-程序员宅基地

文章浏览阅读94次。为什么logical==0?_matlab fat

HTML标签分类及转义字符_ol是单标记还是双标记-程序员宅基地

文章浏览阅读302次。一. HTML标签分类1.根据标签个数分类。 单标签:只有一个标签。 <br>, <hr>,<img>,<meta>, 实现一个特定的功能。 双标签:既有开始标签,也有结束标签。 Html,head,Body,title,h1~h6,p,a,ul,li,ol,strong,em。2.根据标签特性分类(网页效果)。 2.1行属性..._ol是单标记还是双标记

推荐文章

热门文章

相关标签