Coder Social home page Coder Social logo

weiboer's Introduction

https://github.com/princewck/weiboer

Description

一个用于自动发送微博的小插件

headless: false时效果图:

Install

npm i weiboer --save

Config

// config.json 微博账号设置
{
  "username": "185********",
  "password": "your.password",
}
// .weiboer.js 全局puppeteer配置
const path = require('path');
const { PC_AGENTS } = require('./libs/userAgents');

module.exports = {
  // cookie缓存路径,默认会使用上次的cookie,如果有效则不使用账号密码登陆
  'cookies_cache_path': path.resolve(__dirname, '.cookies'), 
  // 浏览器UA
  'default_ua': PC_AGENTS.SAFRI_MAC,
  // puppeteer 登陆选项
  'launch_options': {
    'headless': false,
  },
  'viewport_options': {
    'width': 1366,
    'height': 768,
    'deviceScaleFactor': 1,
  }
}

Usage

const weiboer = require('weiboer');
const path = require('path');
const configFile = path.resolve(__dirname, './config.json'); // 微博账号配置,
// configFile 可以缺省,但要至少确保环境变量中设置了username, password
const weiboHelper = weiboer.init(configFile);
weiboHelper.publish('微博内容', ['./images/01.jps', './images/02.jps']);

Methods

publish

Parameters

  • text:string 微博内容
  • images:Array 微博配图列表,本地图片路径

Results detecting

  weiboHelper.publish('xx', ['./some_img.jpg'])
    .then(() => {
      // success
    })
    .catch(() => {
      // error
    });
  async function someFun() {
    try {
      await  weiboHelper.publish('xx', ['./some_img.jpg']);
    } catch (e) {
      // error handlers
    }
  }

注意⚠️

请勿段时间频繁触发使用账号密码登陆流程,实测发现登陆一定次数后会出现输入账号正确仍然提示账号密码错误的情况。

weiboer's People

Contributors

dependabot[bot] avatar princewck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.