Last active
January 27, 2023 06:56
-
-
Save jrosell/ceedc3a0a1931633ce0c78ad4d0fe6a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{python} | |
import csv | |
import requests | |
import time | |
# Open the CSV file and read the data | |
with open('data.csv', 'r') as file: | |
reader = csv.reader(file) | |
data = [row for row in reader] | |
# Define the login data | |
login_data = { | |
'username': 'your_username', | |
'password': 'your_password' | |
} | |
# Log in to the web app | |
session = requests.Session() | |
session.post('https://example.com/login', data=login_data) | |
# Iterate over the rows of data and send each as a separate form request | |
for row in data: | |
form_data = { | |
'field1': row[0], | |
'field2': row[1], | |
'field3': row[2] | |
} | |
response = session.post('https://example.com/submit-form', data=form_data) | |
print(response.text) | |
time.sleep(5) | |
``` | |
```{r} | |
library(httr2) | |
# Read the CSV file | |
data <- read.csv("data.csv", header = TRUE) | |
# Define the login data | |
login_data <- list(username = "your_username", | |
password = "your_password") | |
# Log in to the web app | |
session <- post("https://example.com/login", body = login_data) | |
# Iterate over the rows of data and send each as a separate form request | |
for(i in 1:nrow(data)){ | |
form_data <- list(field1 = data[i,1], field2 = data[i,2], field3 = data[i,3]) | |
response <- post("https://example.com/submit-form", body = form_data, add_headers("Cookie" = session$headers$`set-cookie`)) | |
print(content(response)) | |
Sys.sleep(5) | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment