Visit url
Function Syntax
buffer visit_url(string page )
buffer visit_url(string page ,boolean use_POST )
- page is the page to visit
- use_POST is true for a POST request and false for a GET request
Returns the HTML from the visited page (not just what is displayed when visiting the page, but all markup) by performing a POST request if use_POST is omitted or true, or a GET request if false. Note that for addresses inside of KoL, it is only necessary to supply the page name for page, and KoLmafia will populate the rest of the url. However, pages outside of KoL require the full url to be supplied for page.
Code Samples
Visits your private character sheet.
visit_url( "charsheet.php" );
Visits google.
visit_url( "http://www.google.com/");
Given a player ID, parse a player's profile for his name.
string getPlayerName( int playerID ) {
string playerName;
// use visit_url() to store the player profile's HTML in a string
string playerProfile = visit_url("/showplayer.php?who=" + playerID);
if ( contains_text(playerProfile, "<td>Sorry, this player could not be found.</td>") ) {
print("Player " + playerID + "does not exist.","red");
return "";
}
// find player name in the string returned by visit_url()
matcher match_name = create_matcher( "<b>([^<]+)</b> \\(#" + playerID + "\\)<br>", playerProfile );
if ( match_name.find() ) {
playerName = match_name.group(1);
}
else {
print("Problem occured while parsing for player name","red");
return "";
}
return playerName;
}
Special
Note that this function returns void if the page does not exist or if the request times-out.
Attention KoLmafia Experts!
We need your help; some details of this function's operation are unknown or unclear.
The following specific questions have been raised:
- Is the special note correct? It appears to sometimes return an empty string & sometimes void; I'm unclear on how the two interact
- There's a 0-argument version; what does it do? Reload the last page?