When I write the HTML to a file, and open the file, it says "The inventory is not available" I tried using a user-agent, but I had no luck. Any help? The result I was hoping for is to grab the entire inventory, and print out the list of a desired page on their inventory to the listbox. (Windows Forms Application, HtmlAgilityPack)
namespace projectWFA
{
public partial class Form1 : Form
{
public string selectedCurrency;
public string urlBase = "http://www.steamcommunity.com/id/";
public string text_username;
// HTMLAGILITYPACK
public HtmlWeb htmlweb;
public HtmlAgilityPack.HtmlDocument htmldocument_pageInventory;
public HtmlAgilityPack.HtmlDocument htmldocument;
public Form1()
{
InitializeComponent();
comboboxCurrency.SelectedIndex = 0;
comboboxPlaceHolder1.SelectedIndex = 0;
comboboxPlaceHolder2.SelectedIndex = 0;
// WEB STUFF
htmlweb = new HtmlWeb();
}
private void Form1_Load(object sender, EventArgs e)
{
selectedCurrency = comboboxCurrency.Items[comboboxCurrency.SelectedIndex].ToString();
Console.Out.WriteLine("selCur: " + selectedCurrency);
}
private void buttonAccept_Click(object sender, EventArgs e)
{
labelPrintUsername.Text = "Loading webpage.. Please wait..";
// LOAD WEBPAGE
htmldocument = htmlweb.Load(urlBase + textboxProfileLink.Text);
Console.Out.WriteLine("Link: " + urlBase + textboxProfileLink.Text);
if (htmldocument != null)
{
Console.Out.WriteLine("Found profile");
HtmlNode node_username = htmldocument.DocumentNode.SelectSingleNode("//span[@class='actual_persona_name']");
if (node_username != null)
{
text_username = node_username.InnerText;
labelPrintUsername.Text = text_username + "'s Inventory";
listboxItems.Items.Clear();
htmldocument_pageInventory = htmlweb.Load(urlBase + textboxProfileLink.Text + "/inventory/");
System.IO.File.WriteAllText(@"C:\Users\...\Desktop\asd.html", htmldocument_pageInventory.DocumentNode.InnerHtml);
}
}
else if (htmldocument == null)
{
Console.Out.WriteLine("Couldn't find profile");
}
}
}
}
To get the page as it would be from using a browser, use this instead:
string data = "";
using (WebClient client = new WebClient())
{
data = client.DownloadString(url);
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
doc.Load(stream);