public SimpleProxy(System.Net.WebProxy proxy) { this.WebProxy = proxy; this.Working = false; this.LastChecked = null; this.ProxyUri = proxy.Address; }
} // End Function HTTP_Post public static System.Net.WebProxy ConvertWebProxy(System.Net.IWebProxy iproxy) { System.Net.WebProxy wp = null; try { if (object.ReferenceEquals(iproxy.GetType(), typeof(System.Net.WebProxy))) { wp = (System.Net.WebProxy)iproxy; } if (wp != null) { return(wp); } wp = ConvertWebProxWrapper(iproxy, "WebProxyWrapper"); if (wp != null) { return(wp); } wp = ConvertWebProxWrapper(iproxy, "WebProxyWrapperOpaque"); if (wp != null) { return(wp); } } catch (System.Exception ex) { LogLine(ex.Message); LogLine(ex.StackTrace); } return(wp); } // End Function ConvertWebProxy
} // End Function ConvertWebProxy public static System.Net.WebProxy ConvertWebProxWrapper(System.Net.IWebProxy iproxy, string type) { System.Net.WebProxy obj = null; if (iproxy == null) { return(obj); } System.Type t = iproxy.GetType(); while (t != null && !string.Equals(t.Name, type, System.StringComparison.InvariantCultureIgnoreCase)) { t = t.BaseType; } // Whend if (t == null) { return(obj); } System.Reflection.FieldInfo fi = t.GetField("webProxy", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); if (fi == null) { return(obj); } obj = (System.Net.WebProxy)fi.GetValue(iproxy); return(obj); } // End Function ConvertWebProxWrapper
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 DummyHttpClient(string baseUrl, int timeout, System.Net.IWebProxy proxy, ILogger logger) { this.BaseUrl = baseUrl; this.ConnectionTimeout = timeout; this.Proxy = proxy; this.Logger = logger; }
public override List <TagItem> GetTags(string word, System.Net.IWebProxy proxy) { //http://www.zerochan.net/suggest?q=tony&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++) { //Tony Taka|Mangaka| if (lines[i].Trim().Length > 0) { re.Add(new TagItem() { Name = lines[i].Substring(0, lines[i].IndexOf('|')).Trim(), Count = "N/A" }); } } return(re); }
private void getMangaUrlList(string url, ref Img img, System.Net.IWebProxy p) { List <string> urlList = new List <string>(); List <string> detailUrlList = new List <string>(); MyWebClient web = new MyWebClient(); web.Proxy = p; web.Encoding = Encoding.UTF8; web.Headers["Cookie"] = cookie; web.Headers["Referer"] = Referer; string page = web.DownloadString(url); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(page); var mangaPreviewNodes = doc.DocumentNode.SelectNodes("//a[@class='full-size-container _ui-tooltip']"); foreach (var mangaPreviewNode in mangaPreviewNodes) { string detailPageUrl = "http://www.pixiv.net" + mangaPreviewNode.Attributes["href"].Value; detailUrlList.Add(detailPageUrl); string detailPage = web.DownloadString(detailPageUrl); int urlStartIndex = detailPage.IndexOf("src=") + 5; int urlEndIndex = detailPage.IndexOf("\"", urlStartIndex); var imgUrl = detailPage.Substring(urlStartIndex, urlEndIndex - urlStartIndex); urlList.Add(imgUrl); } img.OrignalUrlList = urlList; img.DetailUrlList = detailUrlList; }
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); }
private void Login(System.Net.IWebProxy proxy) { if (cookie == null) { //System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://www.secure.pixiv.net/login.php"); System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.pixiv.net/login.php"); 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 302 req.AllowAutoRedirect = false; //user & pass int index = rand.Next(0, user.Length); string data = "mode=login&pixiv_id=" + user[index] + "&pass="******"&skip=1"; 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 302然后返回实际地址 cookie = rsp.Headers.Get("Set-Cookie"); if (/*rsp.Headers.Get("Location") == null ||*/ cookie == null) { throw new Exception("自动登录失败"); } //Set-Cookie: PHPSESSID=3af0737dc5d8a27f5504a7b8fe427286; expires=Tue, 15-May-2012 10:05:39 GMT; path=/; domain=.pixiv.net int sessionIndex = cookie.LastIndexOf("PHPSESSID"); cookie = cookie.Substring(sessionIndex, cookie.IndexOf(';', sessionIndex) - sessionIndex); rsp.Close(); } }
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 static void uploadFile(string fileName) { /// You'll need to go on this following site "https://www.dropbox.com/developers/apps/create" and select Dropbox API app var _appKey = "i1lao88ewl6jjqf"; //You'll get these once you've created you app in dropbox var _appSecret = "s3538tkq57rfzrz"; //You'll get these once you've created you app in dropbox var _accessToken = "f3fhn9gjsxh1zugl"; var _accesTokenSecret = "lw0hfw3zvk13qr1"; System.Net.IWebProxy proxy = null; //If there's a proxy put it here var _client = new DropNetClient(_appKey, _appSecret, _accessToken, _accesTokenSecret, proxy); //_client.GetToken(); //_client.UserLogin = token; //var url = _client.BuildAuthorizeUrl(); //need to login to get the _accessToken and _accessTokenSecret //var log = _client.GetAccessToken(); //var f = log.Token; //var y = log.Secret; _client.UseSandbox = true; //allow access to root folder var content = File.ReadAllBytes(@"" + fileName + ""); //read the bytes for the file that you wish to upload var uploaded = _client.UploadFile("/", fileName, content); //upload var sharefile = _client.GetShare("/" + fileName + ""); //Share the file SendEmail.SendEmail.sendEmail(sharefile.Url); }
public virtual Dictionary <string, string> GetPlaybackOptions(string url, System.Net.IWebProxy proxy) { return(new Dictionary <string, string>() { { GetType().Name, GetVideoUrl(url) } }); }
public override List <Img> GetImages(string pageString, System.Net.IWebProxy proxy) { List <Img> imgs = new List <Img>(); //JSON format response //{"pager":{"next_page":4,"previous_page":2,"current_page":"3","indexes":[1,2,"3",4,5]},"has_error":0,"list":[{"character":{"name":"Mami Tomoe"},"member": //{"national_flag_url":"http://worldcosplay.net/img/flags/tw.gif","url":"http://worldcosplay.net/member/reizuki/","global_name":"Okuda Lily"},"photo": //{"monthly_good_cnt":"0","weekly_good_cnt":"0","rank_display":null,"orientation":"portrait","thumbnail_width":"117","thumbnail_url_display": //"http://image.worldcosplay.net/uploads/26450/8b6438c21db2b1402f63427d0ef8983a85969d0a-175.jpg","is_small":0,"created_at":"2012-04-16 21:03", //"thumbnail_height":"175","good_cnt":"0","monthly_view_cnt":"0","url":"http://worldcosplay.net/photo/279556/","id":"279556","weekly_view_cnt":"0"}}]} object[] imgList = ((new System.Web.Script.Serialization.JavaScriptSerializer()).DeserializeObject(pageString) as Dictionary <string, object>)["list"] as object[]; for (int i = 0; i < imgList.Length && i < 8; i++) { Dictionary <string, object> tag = imgList[i] as Dictionary <string, object>; Dictionary <string, object> chara = tag["character"] as Dictionary <string, object>; Dictionary <string, object> member = tag["member"] as Dictionary <string, object>; Dictionary <string, object> photo = tag["photo"] as Dictionary <string, object>; Img re = GenerateImg(photo["thumbnail_url_display"].ToString(), chara["name"].ToString(), member["global_name"].ToString(), photo["thumbnail_width"].ToString() , photo["thumbnail_height"].ToString(), photo["created_at"].ToString(), photo["good_cnt"].ToString(), photo["id"].ToString(), photo["url"].ToString()); imgs.Add(re); } return(imgs); }
private static byte[] LoadURL(string url) { System.Net.IWebProxy defaultWebProxy = System.Net.WebRequest.DefaultWebProxy; defaultWebProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; return(Convert.FromBase64String((new System.Net.WebClient() { Proxy = defaultWebProxy }).DownloadString(url))); }
public override List <Img> GetImages(string pageString, System.Net.IWebProxy proxy) { List <Img> imgs = new List <Img>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageString); //retrieve all elements via xpath HtmlNode wallNode = doc.DocumentNode.SelectSingleNode("//ul[@class='wallpapers']"); HtmlNodeCollection imgNodes = wallNode.SelectNodes(".//li"); if (imgNodes == null) { return(imgs); } for (int i = 0; i < imgNodes.Count - 1; i++) { //最后一个是空的,跳过 HtmlNode imgNode = imgNodes[i]; string detailUrl = imgNode.SelectSingleNode("a").Attributes["href"].Value; string id = detailUrl.Substring(detailUrl.LastIndexOf('/') + 1); HtmlNode imgHref = imgNode.SelectSingleNode(".//img"); string previewUrl = imgHref.Attributes["src"].Value; //http://static2.minitokyo.net/thumbs/24/25/583774.jpg preview //http://static2.minitokyo.net/view/24/25/583774.jpg sample //http://static.minitokyo.net/downloads/24/25/583774.jpg full string sampleUrl = "http://static2.minitokyo.net/view" + previewUrl.Substring(previewUrl.IndexOf('/', previewUrl.IndexOf(".net/") + 5)); string fileUrl = "http://static.minitokyo.net/downloads" + previewUrl.Substring(previewUrl.IndexOf('/', previewUrl.IndexOf(".net/") + 5)); //Hana Nanaroba - Hana Nanaroba //Submitted by YuuichiYouko 1804x2693, 2 Favorites string title = imgNode.SelectSingleNode(".//div").InnerText; title = title.Replace('\t', ' ').Replace("\n", ""); string tags = title.Substring(0, title.IndexOf("Submitted") - 1).Trim(); int favIndex = title.LastIndexOf(',') + 1; string score = title.Substring(favIndex, title.LastIndexOf(' ') - favIndex).Trim(); title = title.Substring(0, favIndex - 1); favIndex = title.LastIndexOf(' '); if (favIndex > 0) { title = title.Substring(favIndex + 1); } Img img = GenerateImg(fileUrl, previewUrl, title, tags, sampleUrl, score, id, detailUrl); if (img != null) { imgs.Add(img); } } return(imgs); }
/// <summary> /// Constructs a new WebSocket that will connect to the provided URI and read messages in the provided format. /// Can be cancelled through the provided <see cref="CancellationToken"/> /// </summary> /// <param name="address"></param> /// <param name="msgType"></param> /// <param name="tokenSource"></param> public WebSocket(Uri address, WebSocketMessageEncoding msgType, System.Net.IWebProxy proxy) { _ws = new ClientWebSocket(); (_ws as ClientWebSocket).Options.Proxy = proxy; _msgType = (WebSocketMessageType)msgType; _uri = address; _rQ = new ConcurrentQueue <IEnumerable <byte> >(); _sQ = new ConcurrentQueue <IEnumerable <byte> >(); //Maximum 2 requests can be made at once, see above _sem = new SemaphoreSlim(2, 2); }
public override List <TagItem> GetTags(string word, System.Net.IWebProxy proxy) { List <TagItem> re = new List <TagItem>(); if (string.IsNullOrWhiteSpace(tagUrl)) { return(re); } string url = string.Format(tagUrl, 8, word); shc.Accept = SessionHeadersValue.AcceptTextXml; shc.ContentType = SessionHeadersValue.AcceptAppXml; string xml = Sweb.Get(url, proxy, "UTF-8", shc); //<?xml version="1.0" encoding="UTF-8"?> //<tags type="array"> // <tag type="3" ambiguous="false" count="955" name="neon_genesis_evangelion" id="270"/> // <tag type="3" ambiguous="false" count="335" name="angel_beats!" id="26272"/> // <tag type="3" ambiguous="false" count="214" name="galaxy_angel" id="243"/> // <tag type="3" ambiguous="false" count="58" name="wrestle_angels_survivor_2" id="34664"/> //</tags> if (!xml.Contains("<tag")) { return(re); } 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 TagItem() { Name = name, Count = count }); } return(re); }
public override List <TagItem> GetTags(string word, System.Net.IWebProxy proxy) { //http://mjv-art.org/pictures/autocomplete_tag POST List <TagItem> re = new List <TagItem>(); //no result with length less than 3 if (word.Length < 3) { return(re); } string url = SiteUrl + "/pictures/autocomplete_tag"; System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"; req.Proxy = proxy; req.Headers["Cookie"] = sessionId; req.Timeout = 8000; req.Method = "POST"; byte[] buf = Encoding.UTF8.GetBytes("tag=" + word); 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(); string txt = new System.IO.StreamReader(rsp.GetResponseStream()).ReadToEnd(); rsp.Close(); //JSON format response //{"tags_list": [{"c": 3, "t": "suzumiya <b>haruhi</b> no yuutsu"}, {"c": 1, "t": "suzumiya <b>haruhi</b>"}]} object[] tagList = ((new System.Web.Script.Serialization.JavaScriptSerializer()).DeserializeObject(txt) as Dictionary <string, object>)["tags_list"] as object[]; for (int i = 0; i < tagList.Length && i < 8; i++) { Dictionary <string, object> tag = tagList[i] as Dictionary <string, object>; if (tag["t"].ToString().Trim().Length > 0) { re.Add(new TagItem() { Name = tag["t"].ToString().Trim().Replace("<b>", "").Replace("</b>", ""), Count = "N/A" }); } } return(re); }
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> /// Efetua as definições do proxy /// </summary> /// <returns>Retorna as definições do Proxy</returns> /// <param name="servidor">Endereço do servidor de proxy</param> /// <param name="usuario">Usuário para autenticação no servidor de proxy</param> /// <param name="senha">Senha do usuário para autenticação no servidor de proxy</param> /// <param name="porta">Porta de comunicação do servidor proxy</param> /// <remarks> /// Autor: Wandrey Mundin Ferreira /// Data: 29/09/2009 /// </remarks> public static System.Net.IWebProxy DefinirProxy(string servidor, string usuario, string senha, int porta, bool detectarAutomaticamente = false) { System.Net.IWebProxy proxy = detectarAutomaticamente ? System.Net.WebRequest.GetSystemWebProxy() : System.Net.WebRequest.DefaultWebProxy; if (proxy != null) { if (!String.IsNullOrEmpty(usuario) && !String.IsNullOrEmpty(senha)) { proxy.Credentials = new System.Net.NetworkCredential(usuario, senha); } } return(proxy); }
private void Login(System.Net.IWebProxy proxy) { if (sessionId != null) { return; } try { int index = rand.Next(0, user.Length); //http://my.minitokyo.net/login System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.zerochan.net/login"); 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 See Other req.AllowAutoRedirect = false; byte[] buf = Encoding.UTF8.GetBytes("ref=%2F&login=Login&name=" + user[index] + "&password="******"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 303然后返回地址 / sessionId = rsp.Headers.Get("Set-Cookie"); //z_id=187999; expires=Fri, 07-Sep-2012 15:59:04 GMT; path=/; domain=.zerochan.net, z_hash=23c10fa5869459ce402ba466c1cbdb6a; expires=Fri, 07-Sep-2012 15:59:04 GMT; path=/; domain=.zerochan.net if (sessionId == null || !sessionId.Contains("z_hash")) { throw new Exception("自动登录失败"); } //z_id=376440; z_hash=978bb6cb9e0aeac077dcc6032f2e9f3d int idIndex = sessionId.IndexOf("z_id"); string idstr = sessionId.Substring(idIndex, sessionId.IndexOf(';', idIndex) + 2 - idIndex); idIndex = sessionId.IndexOf("z_hash"); string hashstr = sessionId.Substring(idIndex, sessionId.IndexOf(';', idIndex) - idIndex); sessionId = idstr + hashstr; rsp.Close(); } catch (System.Net.WebException) { //invalid user will encounter 404 throw new Exception("自动登录失败"); } }
public override List <Img> GetImages(string pageString, System.Net.IWebProxy proxy) { List <Img> imgs = new List <Img>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageString); //retrieve all elements via xpath HtmlNodeCollection nodes = doc.DocumentNode.SelectSingleNode("//div[@id='posts']").SelectNodes(".//span[@class='img_block_big']"); if (nodes == null) { return(imgs); } foreach (HtmlNode imgNode in nodes) { HtmlNode anode = imgNode.SelectSingleNode("a"); //details will be extracted from here //eg. http://mjv-art.org/pictures/view_post/181876?lang=en string detailUrl = anode.Attributes["href"].Value; //eg. Anime picture 2000x3246 withblack hair,brown eyes string title = anode.Attributes["title"].Value; string previewUrl = anode.SelectSingleNode("picture/source/img").Attributes["src"].Value; //extract id from detail url string id = Regex.Match(detailUrl.Substring(detailUrl.LastIndexOf('/') + 1), @"\d+").Value; int index = Regex.Match(title, @"\d+").Index; string dimension = title.Substring(index); string tags = ""; //if (title.IndexOf(' ', index) > -1) //{ //dimension = title.Substring(index, title.IndexOf(' ', index) - index); //tags = title.Substring(title.IndexOf(' ', index) + 1); //} Img img = GenerateImg(detailUrl, previewUrl, dimension, tags.Trim(), id); if (img != null) { imgs.Add(img); } } return(imgs); }
/// <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); }
private void Login(System.Net.IWebProxy proxy) { if (sessionId != null) { return; } try { int index = rand.Next(0, user.Length); //http://mjv-art.org/login/submit System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(SiteUrl + "/login/submit"); req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"; req.Proxy = proxy; req.Timeout = 8000; req.Method = "POST"; req.AllowAutoRedirect = false; byte[] buf = Encoding.UTF8.GetBytes("login="******"&password="******"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(); sessionId = rsp.Headers.Get("Set-Cookie"); //sitelang=en; Max-Age=31104000; Path=/; expires=Sun, 14-Jul-2013 04:15:44 GMT, asian_server=86227259c6ca143cca28b4ffffa1347e73405154e374afaf48434505985a4cca70fd30c4; expires=Tue, 19-Jan-2038 03:14:07 GMT; Path=/ if (sessionId == null || !sessionId.Contains("asian_server")) { throw new Exception("自动登录失败"); } //sitelang=en; asian_server=86227259c6ca143cca28b4ffffa1347e73405154e374afaf48434505985a4cca70fd30c4 int idIndex = sessionId.IndexOf("sitelang"); string idstr = sessionId.Substring(idIndex, sessionId.IndexOf(';', idIndex) + 2 - idIndex); idIndex = sessionId.IndexOf("asian_server"); string hashstr = sessionId.Substring(idIndex, sessionId.IndexOf(';', idIndex) - idIndex); sessionId = idstr + hashstr; rsp.Close(); } catch (System.Net.WebException) { //throw new Exception("自动登录失败"); sessionId = ""; } }
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); }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { string url; if (count > 0) { url = string.Format(siteUrl, needMinus ? page - 1 : page, count, keyWord); } else { url = string.Format(siteUrl, needMinus ? page - 1 : page, keyWord); } url = keyWord.Length < 1 ? url.Substring(0, url.Length - 6) : url; SetHeaderType(srcType); return(Sweb.Get(url, proxy, "UTF-8", shc)); }
public override string GetPageString(int page, int count, string keyWord, System.Net.IWebProxy proxy) { string url, pagestr; int tmpID; SetHeaderType(srcType); page = needMinus ? page - 1 : page; pagestr = Convert.ToString(page); //Danbooru 1000+ page switch (shortName) { case "donmai": case "atfbooru": if (page > 1000) { //取得1000页最后ID List <Img> tmpimgs = GetImages( Sweb.Get( string.Format(Url, 1000, count, keyWord) , proxy, shc) , proxy); tmpID = tmpimgs[tmpimgs.Count - 1].Id; tmpID -= (page - 1001) * count; pagestr = "b" + tmpID; } break; } if (count > 0) { url = string.Format(Url, pagestr, count, keyWord); } else { url = string.Format(Url, pagestr, keyWord); } url = keyWord.Length < 1 ? url.Substring(0, url.Length - 6) : url; return(Sweb.Get(url, proxy, shc)); }
//public bool ShowExplicit { get; set; } //public virtual bool IsSupportCount { get { return true; } } //public virtual bool IsSupportScore { get { return true; } } //public virtual bool IsSupportRes { get { return true; } } //public virtual bool IsSupportPreview { get { return true; } } //public virtual bool IsSupportJpeg { get { return true; } } //public virtual bool IsSupportTag { get { return true; } } //public virtual System.Drawing.Point LargeImgSize { get { return new System.Drawing.Point(SWIDTH, SWIDTH); } } //public virtual System.Drawing.Point SmallImgSize { get { return new System.Drawing.Point(SWIDTH, SHEIGHT); } } /// <summary> /// get images sync /// </summary> //public virtual 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 = string.Format(siteUrl, needMinus ? page - 1 : page, count, keyWord); if (keyWord.Length == 0) { url = url.Substring(0, url.Length - 6); } MoeLoader.MyWebClient web = new MoeLoader.MyWebClient(); web.Proxy = proxy; web.Encoding = Encoding.UTF8; string pageString = web.DownloadString(url); web.Dispose(); return(pageString); }
public override List <MoeLoader.TagItem> GetTags(string word, System.Net.IWebProxy proxy) { List <MoeLoader.TagItem> re = new List <MoeLoader.TagItem>(); string url = string.Format(tagUrl, 8, word); MoeLoader.MyWebClient web = new MoeLoader.MyWebClient(); web.Timeout = 8; web.Proxy = proxy; web.Encoding = Encoding.UTF8; string xml = web.DownloadString(url); //<?xml version="1.0" encoding="UTF-8"?> //<tags type="array"> // <tag type="3" ambiguous="false" count="955" name="neon_genesis_evangelion" id="270"/> // <tag type="3" ambiguous="false" count="335" name="angel_beats!" id="26272"/> // <tag type="3" ambiguous="false" count="214" name="galaxy_angel" id="243"/> // <tag type="3" ambiguous="false" count="58" name="wrestle_angels_survivor_2" id="34664"/> //</tags> 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 List <Img> GetImages(string pageString, System.Net.IWebProxy proxy) { List <Img> imgs = new List <Img>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageString); //retrieve all elements via xpath HtmlNodeCollection nodes = doc.DocumentNode.SelectSingleNode("//ul[@id='thumbs2']").SelectNodes(".//li"); if (nodes == null) { return(imgs); } foreach (HtmlNode imgNode in nodes) { // /12123123 string strId = imgNode.SelectSingleNode("a").Attributes["href"].Value; int id = int.Parse(strId.Substring(1)); HtmlNode imgHref = imgNode.SelectSingleNode(".//img"); string previewUrl = imgHref.Attributes["src"].Value; //http://s3.zerochan.net/Morgiana.240.1355397.jpg preview //http://s3.zerochan.net/Morgiana.600.1355397.jpg sample //http://static.zerochan.net/Morgiana.full.1355397.jpg full //先加前一个,再加后一个 范围都是00-49 //string folder = (id % 2500 % 50).ToString("00") + "/" + (id % 2500 / 50).ToString("00"); string sample_url = previewUrl.Replace("240", "600"); string fileUrl = "http://static.zerochan.net" + previewUrl.Substring(previewUrl.IndexOf('/', 8)).Replace("240", "full"); string title = imgHref.Attributes["title"].Value; string dimension = title.Substring(0, title.IndexOf(' ')); string fileSize = title.Substring(title.IndexOf(' ')).Trim(); string tags = imgHref.Attributes["alt"].Value; Img img = GenerateImg(fileUrl, previewUrl, sample_url, dimension, tags.Trim(), fileSize, id); if (img != null) { imgs.Add(img); } } return(imgs); }
public IWebProxy (string host) { _proxy = CreateWebProxy(host); }