簡體   English   中英

如何以編程方式復制Chrome Developer Tools中的請求?

[英]How to programmatically replicate a request found in Chrome Developer Tools?

我正在Venmo.com上查看我的余額,但他們一次只顯示3個月,我想得到我的整個交易記錄。

查看Chrome開發者工具,在網絡標簽下,我可以看到https://api.venmo.com/v1/transaction-history?start_date=2017-01-01&end_date=2017-01-31返回JSON的請求。

我想以編程方式迭代時間並發出多個請求並聚合所有事務。 但是,我一直得到401 Unauthorized。

我最初的方法是使用Node.js. 我查看了請求中的cookie並將其復制到secret.txt文件中,然后發送請求:

import fetch from 'node-fetch'
import fs from 'fs-promise'

async function main() {
  try {
    const cookie = await fs.readFile('secret.txt')  
    const options = {
      headers: {
        'Cookie': cookie,
      }, 
    }
    try {
      const response = await fetch('https://api.venmo.com/v1/transaction-history?start_date=2016-11-08&end_date=2017-02-08', options)
      console.log(response)
    } catch(e) {
      console.error(e)
    }
  } catch(e) {
    console.error('please put your cookie in a file called `secret.txt`')
    return
  }
}

這不起作用我嘗試復制所有標題:

const cookie = await fs.readFile('secret.txt')  
const options = {
  headers: {
    'Accept-Encoding': 'gzip, deflate, sdch, br',
    'Accept-Language': 'en-US,en;q=0.8',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Cookie': cookie,
    'Host': 'api.venmo.com',
    'Origin': 'https://venmo.com',
    'Pragma': 'no-cache',
    'Referer': 'https://venmo.com/account/settings/balance/statement?end=02-08-2017&start=11-08-2016',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36',
  }, 
}
try {
  const response = await fetch('https://api.venmo.com/v1/transaction-history?start_date=2016-11-08&end_date=2017-02-08', options)
  console.log(response)
} catch(e) {
  console.error(e)
}

這也行不通。

我甚至嘗試從網站的控制台發出請求並得到401:

fetch('https://api.venmo.com/v1/transaction-history?start_date=2016-11-08&end_date=2017-02-08', {credentials: 'same-origin'}).then(console.log)

所以我的問題是:我在Chrome開發者工具中看到了一個網絡請求。 如何以編程方式提出相同的請求? 最好在Node.js或Python中,這樣我就可以編寫一個自動腳本。

在Chrome開發者工具的網絡標簽中,右鍵單擊該請求,然后單擊“復制”>“復制為cURL(命令)”。 然后,您可以直接使用curl命令編寫腳本,或使用https://curl.trillworks.com/將cURL命令轉換為Python,Node.JS或PHP。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM