'I have issues with cookies in web-scraping - Flutter (Issues with cookies)
GetAttendanceRequest() async {
var client = http.Client();
var posturl = Uri.parse('https://posturl');
var geturl = Uri.parse('https://geturl');
try {
// Getting the cookie 🍪
var postres = await client.post(posturl,body: {'password': 'pswd', 'userid': 'id'});
// saving the cookie in local variable
var RawCookiee = postres.headers.values.elementAt(2).toString().substring(0,42);
// Getting the attendance (web scraping my college website)
// the get request doesn't work it redirects me to the login page again (posturl)
var getres = await client.get(geturl, headers:{"Cookie": RawCookiee});
dom.Document document = parser.parse(getres.body);
final elements = document.getElementsByClassName("ibox");
var Attendance = elements.map((element) => element.getElementsByTagName("h2")[0].innerHtml);
var HoursCompleted = Attendance.toString().substring(9,11);
var HoursAttended = Attendance.toString().substring(43,45);
var Percentage = Attendance.toString().substring(47,52);
}
finally {
client.close();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
