How can I read from a website? C# [duplicate]

2019-09-22 14:17发布

问题:

This question already has an answer here:

  • How can I read from a website? [closed] 1 answer

I'm trying to make a bot, how can I read the value like the 1800 / 1800 from a website?

        Console.WriteLine("Health: ")
        Console.WriteLine("Energy: ")
        Console.WriteLine("Cash: ")
        Console.WriteLine("Level: ")

I'm making a console application, trying to get the value. Like if the health is lower then 1000/1800 then it's going to execute a send key. Like send the key "0" to the website.

Thanks, Prince

回答1:

trying using WebClient.DownloadString

http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadstring(v=vs.110).aspx

WebClient client = new WebClient ();
string reply = client.DownloadString ("http://google.com");

you then parse the document for the things you want. you can use the HTML Agility pack for that

http://html-agility-pack.net