Skip to content

Instantly share code, notes, and snippets.

@SIRprise
Created May 12, 2020 08:41
Show Gist options
  • Save SIRprise/bd577854bdf68c8d6dda85851f15326b to your computer and use it in GitHub Desktop.
Save SIRprise/bd577854bdf68c8d6dda85851f15326b to your computer and use it in GitHub Desktop.
Website parser
using System;
using System.Security.Cryptography;
using System.Text;
using RestSharp;
using RestSharp.Authenticators;
namespace httpsPriceParser
{
class Program
{
public static string CreateMD5(string input)
{
// Use input string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
public static string GetStringBetween(string strSource, string strStart, string strEnd)
{
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
int Start, End;
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
return "";
}
static void Main(string[] args)
{
/*
Console.WriteLine("Hello World!");
var client = new RestClient("https://api.bt.xy/v4");
//client.Authenticator = new HttpBasicAuthenticator("username", "password");
//var request = new RestRequest("statuses/home_timeline.json", DataFormat.Json);
string urlMD5 = CreateMD5("");
var request = new RestRequest("btceur/rates#API_KEY#"+urlMD5, DataFormat.Json);
var response = client.Get(request);
Console.WriteLine("Hello World!");
*/
var client = new RestClient("https://www.bt.xy/de");
var request = new RestRequest("", DataFormat.None);
var response = client.Get(request);
string euroKurs = GetStringBetween(response.Content, "ticker_price", "€").Split('>')[1];
Console.WriteLine(euroKurs);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment