asdf - 在线代码运行


            
执行结果

名称:asdf

当前代码

const rp = require('request-promise')






const vote = async() => {
  return new Promise(async done => {

    const pre = await getResult()
    console.log('投票前:', pre)

    const rs = await rp({
      method: 'get',
      uri: 'https://zjbdtech.zhangyingjinfu.com/cateVote1/?from=groupmessage&isappinstalled=0',
      resolveWithFullResponse: true
    })
    const setCookie = rs.headers['set-cookie'].toString()
    const csrftoken = setCookie.substring(setCookie.indexOf('=') + 1, setCookie.indexOf(';'))
    let i = 0
    while (i < 3) {
      const rrs = await rp({
        method: 'post',
        uri: 'https://zjbdtech.zhangyingjinfu.com/cateVote1/',
        headers: {
          Cookie: `csrftoken=${csrftoken}`,
          Referer: 'https://zjbdtech.zhangyingjinfu.com/cateVote1/?from=groupmessage&isappinstalled=0',
          Host: 'zjbdtech.zhangyingjinfu.com',
          Origin: 'https://zjbdtech.zhangyingjinfu.com',
          'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
          'X-Requested-With': 'XMLHttpRequest'
        },
        formData: {
          checked: 69,
          csrfmiddlewaretoken: csrftoken
        },
      })
      console.log(i + 1, '投票成功')


      const random = (1000 * 10 * Math.random()).toFixed(2)
      console.log(`随机等待${random/1000}秒`)
      await new Promise(resolve => {
        setTimeout(function() {
          resolve()
        }, random)
      })

      i++
    }

    const aft = await getResult()
    console.log('投票后:', aft)
    done()
  })
}


const getResult = async() => {
  return new Promise(async resolve => {
    let rs = await rp.get('https://zjbdtech.zhangyingjinfu.com/resultVote1/')
    rs = rs.split('<p class="p2">杭州数澜科技有限公司<span>')[1]
    rs = rs.substring(0, rs.indexOf('票'))
    resolve(rs)
  })
}

// getResult()

const go = async() => {
  let i = 1
  while (i <= 10) {
    console.log(`开始第${i}次刷票`)
    await vote()


    const random = (1000 * 20 * Math.random()).toFixed(2)
    console.log(`第${i}次刷票完成,随机等待${random/1000}秒`)
    await new Promise(resolve => {
      setTimeout(function() {
        resolve()
      }, random)
    })
    i++
  }
}

go()