我如何在"内发布"一个HTML会话?
所以在我通过a <- rvest::html_session(url)
我试过了:
library(httr)
POST(path,
add_headers(setNames(as.character(headers(a)), names(headers(a)))),
set_cookies(setNames(cookies(a)$value, cookies(a)$name)),
body = list(...),
encode = "json")
但这可以处理我的请求,因为我没有登录。有什么建议吗?
我正在寻找像POST(session, path, body, ...)
答案 0 :(得分:6)
好的,经过一番挖掘,我用以下方法解决了它:
// Week 7 Assignment 2
#include <iostream>
#include <iomanip>
using namespace std;
// Function Prototypes
int getTotal(int[][COLS]);
// Global Variables
const int ROWS = 4;
const int COLS = 4;
const int NUM_DIVS = 5;
const int NUM_QTRS = 5;
int sales[ROWS][COLS];
int totalSales;
string division[NUM_DIVS] = { "North", "South", "East", "West", "Quarter Total" };
string quarters[NUM_QTRS] = { "Quarter 1", "Quarter 2", "Quarter 3", "Quarter 4" };
int total;
int main()
{
// Variables
cout << "This program will calculate information about sales during a year." << endl;
// Loops to fill the array
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the North during Quarter " << (count + 1) << ": $";
cin >> sales[0][count];
}
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the South during Quarter " << (count + 1) << ": $";
cin >> sales[1][count];
}
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the East during Quarter " << (count + 1) << ": $";
cin >> sales[2][count];
}
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the West during Quarter " << (count + 1) << ": $";
cin >> sales[3][count];
}
total = getTotal(sales, 4);
return 0;
}
// Function to get the total of everything in the array
int getTotal(int sales[][COLS])
{
int totAl = 0;
for (int count = 0; count < ROWS; count++)
{
for (int count = 0; count < COLS; count++)
totAl += sales[count][count];
return totAl;
}
}
x %>% rvest:::request_POST(url,
config(referer = x$url),
user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36"),
body = list(...),
encode = "form")
内部使用
rvest:::request_POST