C# 获取网站的 HTML 代码不起作用

C# Fetching the HTML Code of a website does not work

我一直在尝试下载某个网站的 html 源代码,以便更准确地从这个 URL:

http://steamcommunity.com/market/search?q=&category_730_ItemSet[]=any&category_730_TournamentTeam[]=any&category_730_Weapon[]=any&category_730_Quality[]=tag_normal&appid=730#p10_price_desc

当我将此 URL 放入我的网络浏览器 (Firefox) 时,它会将我带到 Steam 市场的第 10 页,因为在 URL 的末尾,它显示 'p10'.当我将 10 替换为 12 时,它会将我带到第 12 页。但是,当我尝试在 C# 中使用此代码下载第 10 页时,

WebClient webClient = new WebClient();
string pageURL = downloadURL + getURLEnding(currentPage);

string html = webClient.DownloadString(pageURL);
var doc = new HtmlDocument();
doc.LoadHtml(html);

似乎忽略了url的那一点。无论我用什么数字替换 10,我总是得到相同的结果。为什么?

你会得到相同的结果,因为 Steam 的页面实际上使用 AJAX 获取结果,这意味着你想要的内容不在你得到的页面中。

这是第10页时浏览器获取的URL(结果在JSON format中):

http://steamcommunity.com/market/search/render/?query=&start=90&count=10&search_descriptions=0&sort_column=price&sort_dir=desc&appid=730&category_730_ItemSet%5B%5D=any&category_730_TournamentTeam%5B%5D=any&category_730_Weapon%5B%5D=any&category_730_Quality%5B%5D=tag_normal

注意这个URL中的start参数,是根据页码计算的