当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.IndexOf方法代码示例

本文整理汇总了C#中System.Net.WebClient.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.IndexOf方法的具体用法?C# WebClient.IndexOf怎么用?C# WebClient.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.IndexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainTextFetcher

 public MainTextFetcher(string URL, string startingEnclosure, string endingEnclosure)
 {
     //Download the HTML code from given URL
     string fetchedHTML = new WebClient().DownloadString(URL).ToString();
     //Search for the first occurance of first tag
     int firstPos = fetchedHTML.IndexOf(startingEnclosure);
     int secondPos = fetchedHTML.IndexOf(endingEnclosure, firstPos);
     //Fetch only the text of interest
     mainText = fetchedHTML.Substring(firstPos + startingEnclosure.Length, secondPos - firstPos - startingEnclosure.Length);
 }
开发者ID:zeav,项目名称:ProgTek-WebCrawler,代码行数:10,代码来源:MainTextFetcher.cs

示例2: MainTextFetcher

 /// <summary>
 /// Fetches text from a website and gets only the text between the two Tags.
 /// </summary>
 /// <param name="URL">Website URL (with HTTP)</param>
 /// <param name="startingEnclosure">Starting Tag</param>
 /// <param name="endingEnclosure">Stop Tag</param>
 /// <returns></returns>
 public string MainTextFetcher(string URL, string startingEnclosure, string endingEnclosure)
 {
     //Download the HTML code from given URL
     string fetchedHTML = new WebClient().DownloadString(URL).ToString();
     //Search for the first occurance of first tag
     int firstPos = fetchedHTML.IndexOf(startingEnclosure);
     if (firstPos < 0) { Console.WriteLine("Main text fetch failed (1)."); return ""; }
     int secondPos = fetchedHTML.IndexOf(endingEnclosure, firstPos);
     if (secondPos < 0) { Console.WriteLine("Main text fetch failed (2)."); return ""; }
     //Fetch only the text of interest
     return fetchedHTML.Substring(firstPos + startingEnclosure.Length, secondPos - firstPos - startingEnclosure.Length);
 }
开发者ID:zeav,项目名称:ProgTek-WebCrawler,代码行数:19,代码来源:RSSreader.cs

示例3: CheckForInternetConnection

 private bool CheckForInternetConnection()
 {
     try
     {
         string str = new WebClient().DownloadString("http://labpp.org/check/internet/connection/");
         int posStart = str.IndexOf("PublicIP\":\"") + 11;
         int posEnd = str.IndexOf("\"}]");
         string newIP = str.Substring(posStart, posEnd - posStart);
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:solsetmary,项目名称:Makhzan,代码行数:15,代码来源:formLoginForm.cs

示例4: Index

        public ActionResult Index(string folderPath, string url) {
            var viewModel = new OEmbedViewModel {
                Url = url,
                FolderPath = folderPath
            };

            try {
                // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">

                var source = new WebClient().DownloadString(url);

                // seek type="text/xml+oembed" or application/xml+oembed
                var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                if (oembedSignature == -1) {
                    oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
                }
                if (oembedSignature != -1) {
                    var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<');
                    var tagEnd = source.IndexOf('>', oembedSignature);
                    var tag = source.Substring(tagStart, tagEnd - tagStart);
                    var matches = new Regex("href=\"([^\"]+)\"").Matches(tag);
                    if (matches.Count > 0) {
                        var href = matches[0].Groups[1].Value;
                        try {
                            var content = new WebClient().DownloadString(Server.HtmlDecode(href));
                            viewModel.Content = XDocument.Parse(content);
                        }
                        catch {
                            // bubble exception
                        }
                    }
                }
            }
            catch {
                return View(viewModel);
            }

            return View(viewModel);
        }
开发者ID:jgtaveras,项目名称:Coevery,代码行数:39,代码来源:OEmbedController.cs

示例5: GetSpecInfo

 static void GetSpecInfo()
 {
     String GameInfo = new WebClient().DownloadString(BaseUrl + RegionTag + UrlPartial + ObjectManager.Player.Name);
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(SearchString) + SearchString.Length);
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
     Key = GameInfo.Substring(0, GameInfo.IndexOf(" "));
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
     GameId = GameInfo.Substring(0, GameInfo.IndexOf(" "));
     GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
     PlatformId = GameInfo.Substring(0, GameInfo.IndexOf(" "));
 }
开发者ID:kampfi,项目名称:SAwarenessBeta,代码行数:11,代码来源:SpecUtils.cs

示例6: GetWebcamImage

        public static string GetWebcamImage(string webcamsTravelURL)
        {
            try
            {
                string page = new WebClient().DownloadString(webcamsTravelURL);

                int lb = page.IndexOf("http://images.webcams.travel/thumbnail/");
                if (lb == -1)
                    return "";
                else
                {
                    int ub = page.IndexOf('"', lb);
                    if (ub == -1)
                        return "";
                    else
                        return page.Substring(lb, ub - lb).Replace("/thumbnail/", "/webcam/");
                }
            }
            catch (Exception exc)
            {
                Exception = exc;
                return "";
            }
        }
开发者ID:Winterstark,项目名称:Adjutant,代码行数:24,代码来源:classWeather.cs

示例7: Robots

        public Robots(string authority)
        {
            string robotsTXTURL = authority + "/robots.txt";
            content = new WebClient().DownloadString(robotsTXTURL);

            int index = content.IndexOf("User-agent: *");
            if (index >= 0)
            {
                string disallowedContent = content.Substring(index);
                foreach (Match match in Regex.Matches(disallowedContent, @"Disallow:\s*([/-_.A-Za-z0-9]+)"))
                {
                    disallowed.Add(Urls.BuildAbsUrl(robotsTXTURL, match.Groups[1].Value));
                }
            }

            excludeUrlsWithoutToken = "";
        }
开发者ID:kxchiu,项目名称:INFO344,代码行数:17,代码来源:[PA+4]+Robots.cs

示例8: ConvertFromTo

        public static Decimal ConvertFromTo(string fromCurrency, string toCurrency)
        {
            if (!AllSymbols().Contains(fromCurrency))
                throw new CurrencyDoesNotExistException(fromCurrency);
            if (!AllSymbols().Contains(toCurrency))
                throw new CurrencyDoesNotExistException(toCurrency);
            var url = String.Format(
                "http://www.gocurrency.com/v2/dorate.php?"
                + "inV=1&from={0}&to={1}&Calculate=Convert",
                fromCurrency, toCurrency);
            var client = new WebClient();
            var result = new WebClient().DownloadString(url);

            var index = result.IndexOf("<div id=\"converter_results\"><ul><li>");
            var theGoodStuff = result.Substring(index);
            var startIndex = theGoodStuff.IndexOf("<b>") + 3;
            var endIndex = theGoodStuff.IndexOf("</b>");
            var importantStuff = theGoodStuff.Substring(startIndex, endIndex - startIndex);
            var parts = importantStuff.Split('=');
            var almostValue = parts[1].Trim().Split(' ')[0];
            return Decimal.Parse(almostValue, new CultureInfo("en"));
        }
开发者ID:alexbepple,项目名称:CurrencyConversion-CSharp-MSTest,代码行数:22,代码来源:CurrencyConverter.cs

示例9: GetForecast

        public static Report[] GetForecast(string location, string language, bool metric, int nDays, bool hourly)
        {
            string url;
            if (!hourly)
                url = constructWeathermapURL("http://api.openweathermap.org/data/2.5/forecast/daily?q=", location, language, metric, nDays);
            else
                url = constructWeathermapURL("http://api.openweathermap.org/data/2.5/forecast?q=", location, language, metric, 0);

            string resp = new WebClient().DownloadString(url);
            resp = resp.Substring(resp.IndexOf("\"list\":[{") + 9);

            string[] segments = resp.Split(new string[] { "},{" }, StringSplitOptions.RemoveEmptyEntries);

            int n = segments.Length;
            if (hourly)
                n = Math.Min(n, 8 * nDays + 1);

            Report[] reports = new Report[n];
            for (int i = 0; i < n; i++)
                reports[i] = buildReport(segments[i], hourly, metric);

            return reports;
        }
开发者ID:Winterstark,项目名称:Adjutant,代码行数:23,代码来源:classWeather.cs

示例10: Post

            public Post(string title, string url, string permalink, string user, string subreddit, string score, string nComments, string created, string thumbnail)
            {
                this.title = title;
                this.url = url;
                this.permalink = "http://www.reddit.com" + permalink;
                this.user = user;
                this.subreddit = "/r/" + subreddit;
                this.score = int.Parse(score);
                this.nComments = int.Parse(nComments);
                this.created = Misc.ConvertFromUnixTime(created);

                if (url.Contains("imgur") && !url.Contains("imgur.com/a/"))
                {
                    if (url[url.Length - 4] != '.')
                    {
                        //find image extension
                        if (url.Contains("/gallery/"))
                            url = url.Replace("/gallery/", "/");

                        url = "http://api.imgur.com/oembed.json?url=" + url;

                        string jsonFile = new WebClient().DownloadString(url);

                        if (jsonFile.Contains("\"url\":\""))
                        {
                            int lb = jsonFile.IndexOf("\"url\":\"") + 7;
                            int ub = jsonFile.IndexOf('"', lb);
                            url =  jsonFile.Substring(lb, ub - lb);
                            url = Regex.Unescape(url);
                        }
                        else
                        {
                            //no extension data present in xml file
                            url = this.url; //reset url

                            if (thumbnail != "")
                                image = "<image=" + thumbnail + ">"; //use thumbnail
                            else
                                image = "";
                            return;
                        }
                    }

                    if (!url.Contains("i."))
                        url = url.Replace("imgur.com", "i.imgur.com");

                    url = url.Insert(url.Length - 4, "l"); //download large version

                    image = "<image=" + url + ">";
                }
                else
                    image = "<image=" + thumbnail + ">";
            }
开发者ID:Winterstark,项目名称:Adjutant,代码行数:53,代码来源:classReddit.cs

示例11: Wallhaven

        private static string Wallhaven(string url)
        {
            if (Regex.IsMatch(url, @"http://alpha.wallhaven.cc/wallpaper/\d+"))
            {
                string contents = new WebClient().DownloadString(url);
                int index = contents.IndexOf(@"content=""//", StringComparison.Ordinal);
                if (index != -1)
                {
                    index += 9;
                    return "http:" + contents.Substring(index,
                               contents.IndexOf(@"""", index, StringComparison.Ordinal) - index);
                }

                throw new Exception("Perhaps wallhaven changed their html pages?");
            }

            return url;
        }
开发者ID:JulyMoon,项目名称:paperwallz,代码行数:18,代码来源:MainWindow.cs

示例12: WebsiteTranslate

        public static string WebsiteTranslate(string input, string sourceLanguage, string targetLanguage)
        {
            input = input.Replace(Environment.NewLine, "<br/>");
            input = input.Replace("'", "&apos;");
            string address = string.Format("http://translate.google.com/?hl=en&eotf=1&sl={0}&tl={1}&q={2}", sourceLanguage, targetLanguage, 
                HttpUtility.UrlEncode(input));

            string str2 = "";

            try
            {
                str2 = new WebClient 
                { 
                    Proxy = null, 
                    Encoding = Encoding.Default 
                }.DownloadString(address);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                str2 = input;
            }

            Encoding enc = Encoding.Default;
            StringBuilder builder = new StringBuilder();
            int index = str2.IndexOf("charset=");
            if (index > 0)
            {
                int idx2 = str2.IndexOf("\"", index);
                if (idx2 > 0)
                {
                    enc = Encoding.GetEncoding(str2.Substring(index + 8, (idx2 - index) - 8).ToLowerInvariant().Trim());
                }
            }
            index = str2.IndexOf("<span id=result_box");
            if (index > 0)
            {
                index = str2.IndexOf("<span title=", index);
                while (index > 0)
                {
                    index = str2.IndexOf(">", index);
                    if (index > 0)
                    {
                        index++;
                        int num2 = str2.IndexOf("</span>", index);
                        string str15 = str2.Substring(index, num2 - index);
                        string str4 = HttpUtility.HtmlDecode(enc.GetString(Encoding.Default.GetBytes(str15))).Replace(" </ P>", "</ p>").Replace(" <P>", "<p>").Replace(" <P >", "<p>").Replace(" < P >", "<p>").Replace(" </ p>", "</p>").Replace("</ p>", "</p>").Replace("</ P>", "</p>").Replace("</P>", "</p>").Replace("< /P >", "</p>");
                        builder.Append(str4);
                        index = str2.IndexOf("<span title=", index);
                    }
                }
            }
            string str5 = builder.ToString().Replace(" <br/>", Environment.NewLine).Replace("<br/>", Environment.NewLine).Replace("<br />", Environment.NewLine).Replace("< p >", "<p>").Replace("< p>", "<p>").Replace("<p >", "<p>").Replace("</ p>", "</p>").Replace("< / p >", "</p>").Replace("< / p>", "</p>").Replace(" </p>", "</p>").Replace(" </p>", "</p>").Replace("</p>  ", "</p>").Replace("</p> ", "</p>").Replace("</p> ", "</p>").Replace("</p><p>", "@__P_TAG").Replace("</p>", "</p><p>").Replace("@__P_TAG", "</p><p>");
            int length = str5.LastIndexOf("<p>");
            if (length > 0)
            {
                str5 = str5.Substring(0, length);
            }
            return str5;
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:60,代码来源:EntryNameDialog.cs

示例13: Get

        public object Get(string id, string feed = "feed", int limit = 20)
        {
            var appId = ConfigurationManager.AppSettings[Constants.FacebookAppIdKey];
            var appSecret = ConfigurationManager.AppSettings[Constants.FacebookAppSecretKey];

            var pageId = id;

            if (limit > 250)
                limit = 250;

            const string fields = "id,message,picture,link,name,description,type,icon,created_time,from,object_id,likes,comments";

            var authUrl = $"https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={appId}&client_secret={appSecret}";

            var accessToken = new WebClient().DownloadString(authUrl);
            accessToken = accessToken.Substring(accessToken.IndexOf('=') + 1);

            var pageUrl = $"https://graph.facebook.com/v2.3/{pageId}?key=value&access_token={accessToken}&fields=id,link,name";

            var pageObject = new WebClient().DownloadString(pageUrl);

            dynamic pageDetails = JObject.Parse(pageObject);

            var pageLink = pageDetails.link ?? string.Empty;
            var pageName = pageDetails.name ?? string.Empty;

            var graphUrl = $"https://graph.facebook.com/v2.3/{pageId}/{feed}?key=value&access_token={accessToken}&fields={fields}&limit={limit}";
            var graphObject = new WebClient().DownloadString(graphUrl);
            dynamic parsedJson = JObject.Parse(graphObject);
            var pagefeed = parsedJson.data;

            var response = new
            {
                responseData = new {
                    feed = new {
                        link = string.Empty,
                        entries = new List<dynamic>()
                    }
                }
            };

            foreach (var data in pagefeed)
            {
                string message;
                if (!string.IsNullOrEmpty((string)data.message))
                {
                    message = ((string) data.message).Replace("\n", "<br />");
                }
                else if (!string.IsNullOrEmpty((string)data.story))
                {
                    message = data.story;
                }
                else
                {
                    message = string.Empty;
                }

                if (!string.IsNullOrEmpty((string)data.description))
                {
                    message += " " + data.description;
                }

                string link = data.link ?? string.Empty;
                string image = data.picture ?? string.Empty;
                string type = data.type ?? string.Empty;

                if (type == "status" && !string.IsNullOrEmpty((string)data.story))
                {
                    continue;
                }

                if ((data.object_id == null) && (type != "video"))
                {
                    var picId = image.Split('_');
                    if (picId.Length > 0)
                    {
                        data.object_id = picId[0];
                    }
                }

                if (data.object_id != null)
                {
                    if (!image.Contains("safe_image.php") && Regex.IsMatch((string)data.object_id, @"^\d+$"))
                    {
                        image = $"https://graph.facebook.com/{data.object_id}/picture?type=normal";
                    }
                }

                response.responseData.feed.entries.Add(new {
                    pageLink,
                    pageName,
                    link,
                    content = message,
                    thumb = image,
                    data.comments,
                    publishedDate = data.created_time //might need to change, original PHP date format: D, d M Y H:i:s O
                });
            }

            return response;
//.........这里部分代码省略.........
开发者ID:EndzoneSoftware,项目名称:UmbracoSocialPluginAdapters,代码行数:101,代码来源:FacebookController.cs

示例14: SubmitCaptchaAsyncDoWork

 private void SubmitCaptchaAsyncDoWork(object sender, DoWorkEventArgs e)
 {
     CSubmitCaptchaData argument = (CSubmitCaptchaData)e.Argument;
     string url = argument.url;
     DateTime tm = argument.tm;
     string str = "";
     try
     {
         str = new WebClient().DownloadString(url);
     }
     catch (Exception)
     {
         return;
     }
     if (str.IndexOf("Your answer was correct.") != -1 || str.IndexOf("Réponse correcte") != -1)//Add || and your local language here.
     {
         uint index = (uint)str.IndexOf("cols=\"100\">");
         uint num2 = (uint)str.IndexOf("<", (int)(((int)index) + 1));
         captchas.Add(new CCaptcha(str.Substring(((int)index) + 11, ((int)(num2 - index)) - 11), tm));
     }
 }
开发者ID:hurr,项目名称:DelayClose,代码行数:21,代码来源:Form1.cs

示例15: GetShippingOption

        private List<ShippingOption> GetShippingOption()
        {
            string request = _isDomenic
                ? UrlDomenic + GetXmlDomenicPackage()
                : UrlInternational + GetXmlInternationalPackage();

            string xml = new WebClient().DownloadString(request);
            if (xml.Contains("<Error>"))
            {
                int idx1 = xml.IndexOf("<Description>") + 13;
                int idx2 = xml.IndexOf("</Description>");
                string errorText = xml.Substring(idx1, idx2 - idx1);

                Debug.LogError(new Exception("USPS Error returned: " + errorText), false);
            }

            return ParseResponseMessage(xml);
        }
开发者ID:AzarinSergey,项目名称:learn,代码行数:18,代码来源:Usps.cs


注:本文中的System.Net.WebClient.IndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。