public static string ObtainImageInfo(Uri url, string text) { try { var client = new CookieWebClient(); client.Headers[HttpRequestHeader.UserAgent] = FakeUserAgent; // alibi-visit the image search page to get the cookies client.Headers[HttpRequestHeader.Referer] = GoogleHomepageUrl.ToString(); client.DownloadData(GoogleImageSearchUrl); // fetch the actual info var searchUrl = new Uri(string.Format( GoogleImageSearchByImageUrlPattern, Util.UrlEncode(url.ToString(), Util.Utf8NoBom, true) )); client.Headers[HttpRequestHeader.Referer] = GoogleImageSearchUrl.ToString(); var responseBytes = client.DownloadData(searchUrl); var parseMe = EncodingGuesser.GuessEncodingAndDecode(responseBytes, null, null); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(parseMe); var foundHints = htmlDoc.DocumentNode.QuerySelectorAll(".qb-bmqc .qb-b"); foreach (var hint in foundHints) { return(string.Format("{0} ({1})", text, HtmlEntity.DeEntitize(hint.InnerText))); } return(text); } catch (Exception ex) { Logger.Warn("image info", ex); return(text); } }
public void GetVcodePic() { ////生成图片验证码 ////生成随机数列 CookieWebClient client = new CookieWebClient(); client.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"); client.Headers.Add("Accept-Language", "zh-CN"); client.Headers.Add("Accept", "*/*"); client.Headers.Add("Accept-Encoding", "gzip, deflate"); TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1); client.Cookies = cc;//带Cookie访问 string ticks = ts.Ticks.ToString().Substring(0, 13); byte[] bytes = client.DownloadData("http://weibo.com/aj/pincode/pin?_wv=5&type=rule&lang=zh-cn&ts=" + ticks); MemoryStream ms = new MemoryStream(bytes); // MemoryStream创建其支持存储区为内存的流。 //MemoryStream属于System.IO类 ms.Position = 0; Image img = Image.FromStream(ms); this.pictureBox1.Image = img; }