-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π **Changelog: Version X.X.X** π **Enhancements:** - β¨ Upgraded to the latest approach for handling post requests, which now support both JSON and x-www-form-urlencoded formats. - β Implemented extensive error handling capabilities to improve overall stability. - π Updated JSDocs for all methods, enhancing code documentation and clarity. - β‘οΈ Automatically converts sessionId to session, ensuring smooth updates without major disruptions. - β Added new parameters to enhance functionality and customization options. - β Introduced three new methods: `validCookies()`, `isJSON()`, and `isFormData()`, providing additional utility. - β° Extended timeout duration to allow sufficient waiting time for response handling. π **Other Changes:** - π Various performance optimizations and bug fixes to improve overall reliability. - π Minor code refactoring and improvements for better maintainability. π **And more exciting updates!**
- Loading branch information
1 parent
78aba2e
commit 816ed4b
Showing
5 changed files
with
795 additions
and
131 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
[ | ||
"UnitedStates", | ||
"Canada", | ||
"Afghanistan", | ||
"Albania", | ||
"Algeria", | ||
"Argentina", | ||
"Armenia", | ||
"Aruba", | ||
"Australia", | ||
"Austria", | ||
"Azerbaijan", | ||
"Bahamas", | ||
"Bahrain", | ||
"Bangladesh", | ||
"Belarus", | ||
"Belgium", | ||
"BosniaandHerzegovina", | ||
"Brazil", | ||
"BritishVirginIslands", | ||
"Brunei", | ||
"Bulgaria", | ||
"Cambodia", | ||
"Cameroon", | ||
"Canada", | ||
"Chile", | ||
"China", | ||
"Colombia", | ||
"CostaRica", | ||
"Croatia", | ||
"Cuba", | ||
"Cyprus", | ||
"Czechia", | ||
"Denmark", | ||
"DominicanRepublic", | ||
"Ecuador", | ||
"Egypt", | ||
"ElSalvador", | ||
"Estonia", | ||
"Ethiopia", | ||
"Finland", | ||
"France", | ||
"Georgia", | ||
"Germany", | ||
"Ghana", | ||
"Greece", | ||
"Guatemala", | ||
"Guyana", | ||
"HashemiteKingdomofJordan", | ||
"HongKong", | ||
"Hungary", | ||
"India", | ||
"Indonesia", | ||
"Iran", | ||
"Iraq", | ||
"Ireland", | ||
"Israel", | ||
"Italy", | ||
"Jamaica", | ||
"Japan", | ||
"Kazakhstan", | ||
"Kenya", | ||
"Kosovo", | ||
"Kuwait", | ||
"Latvia", | ||
"Liechtenstein", | ||
"Luxembourg", | ||
"Macedonia", | ||
"Madagascar", | ||
"Malaysia", | ||
"Mauritius", | ||
"Mexico", | ||
"Mongolia", | ||
"Montenegro", | ||
"Morocco", | ||
"Mozambique", | ||
"Myanmar", | ||
"Nepal", | ||
"Netherlands", | ||
"NewZealand", | ||
"Nigeria", | ||
"Norway", | ||
"Oman", | ||
"Pakistan", | ||
"Palestine", | ||
"Panama", | ||
"PapuaNewGuinea", | ||
"Paraguay", | ||
"Peru", | ||
"Philippines", | ||
"Poland", | ||
"Portugal", | ||
"PuertoRico", | ||
"Qatar", | ||
"RepublicofLithuania", | ||
"RepublicofMoldova", | ||
"Romania", | ||
"Russia", | ||
"SaudiArabia", | ||
"Senegal", | ||
"Serbia", | ||
"Seychelles", | ||
"Singapore", | ||
"Slovakia", | ||
"Slovenia", | ||
"Somalia", | ||
"SouthAfrica", | ||
"SouthKorea", | ||
"Spain", | ||
"SriLanka", | ||
"Sudan", | ||
"Suriname", | ||
"Sweden", | ||
"Switzerland", | ||
"Syria", | ||
"Taiwan", | ||
"Tajikistan", | ||
"Thailand", | ||
"TrinidadandTobago", | ||
"Tunisia", | ||
"Turkey", | ||
"Uganda", | ||
"Ukraine", | ||
"UnitedArabEmirates", | ||
"UnitedKingdom", | ||
"UnitedStates", | ||
"Uzbekistan", | ||
"Venezuela", | ||
"Vietnam", | ||
"Zambia" | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const Scrappey = require('.'); | ||
|
||
// Replace 'YOUR_API_KEY' with your Scrappey API key | ||
const apiKey = 'YOUR_API_KEY'; | ||
|
||
// Create an instance of Scrappey | ||
const scrappey = new Scrappey(apiKey); | ||
|
||
function getQueryString(object) { | ||
const queryString = Object.keys(object) | ||
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(object[key])) | ||
.join('&'); | ||
return queryString; | ||
} | ||
|
||
async function run() { | ||
try { | ||
// Create a session | ||
const sessionRequest = await scrappey.createSession(); | ||
const { session } = sessionRequest; | ||
|
||
console.log('Created Session:', session); | ||
|
||
// Make a GET request | ||
const getRequestResult = await scrappey.getRequest({ | ||
url: 'https://reqres.in/api/users', | ||
session, | ||
}); | ||
console.log('GET Request Result:', getRequestResult); | ||
|
||
// Make a POST request using FormData | ||
const postFormData = { username: 'user123', password: 'pass456' }; | ||
const postRequestResultForm = await scrappey.postRequest({ | ||
url: 'https://reqres.in/api/users', | ||
postData: getQueryString(postFormData), | ||
session | ||
}); | ||
console.log('POST Request Result (FormData):', postRequestResultForm); | ||
|
||
// Make a POST request using JSON data | ||
const postJsonData = { email: 'user@example.com', password: 'pass123' }; | ||
const postRequestResultJson = await scrappey.postRequest({ | ||
url: 'https://reqres.in/api/users', | ||
postData: JSON.stringify(postJsonData), | ||
headers: { | ||
'Content-Type': 'application/json', // Optional. To avoid issues please still add if you send JSON Data. | ||
}, | ||
session, | ||
// customHeaders: { | ||
// "auth": "token" | ||
// }, | ||
// proxyCountry: "UnitedStates" | ||
// & more! | ||
}); | ||
console.log('POST Request Result (JSON):', postRequestResultJson); | ||
|
||
// Manually destroy the session (automatically destroys after 4 minutes) | ||
await scrappey.destroySession(session); | ||
console.log('Session destroyed.'); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
run(); |
Oops, something went wrong.