public IActionResult Index()
{
var _result = GetHTMLByURL("https://buff.163.com/market/goods?goods_id=835707&from=market#tab=selling");
return View();
}
public static string GetHTMLByURL(string url)
{
try
{
System.Net.WebRequest wRequest = System.Net.WebRequest.Create(url);
wRequest.ContentType = "text/html; charset=utf-8";
wRequest.Method = "get";
wRequest.UseDefaultCredentials = true;
var task = wRequest.GetResponseAsync();
System.Net.WebResponse wResp = task.Result;
System.IO.Stream respStream = wResp.GetResponseStream();
using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding("utf-8")))
{
return reader.ReadToEnd();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return string.Empty;
}
}
使用 Selenium.WebDriver 操作获取内容