06
Nov
HtmlAgilityPack User Agent / HttpWebRequest object
using System; using HtmlAgilityPack; using System.Net; class LbHtmlWeb : HtmlWeb { private readonly string USER_AGENT = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; public LbHtmlWeb() { this.PreRequest += delegate(HttpWebRequest request) { request.UserAgent = USER_AGENT; return true; }; } //… }
Now that was easy! Pretty spiffy that HtmlWeb exposes that event.
Please let me at the HttpWebRequest.
Don't do this (RSS Toolkit, I'm talking to you):
XmlDocument doc = new XmlDocument();
doc.Load(url);
=(
November 11th, 2007 at 3:31 pm
[...] Matt Hinze has posted code for a snazzy HtmlAgilityPack User Agent. [...]