Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm looking for a C# "one-liner" (need not strictly be a single line, but very short is preferable) way to download an RSS feed from a given HTTP URL, and extract specific data. Robustness be damned. Something that doesn't require any external libraries.
Specifically I want to count the number of <item>s in the RSS. But some kind of LINQ method that could be reused to, say for example, return a list of the item <title> elements would be most useful, if it can be kept short.
Regex.Matches(new WebClient().DownloadString("http://stackoverflow.com/feeds/question/7180063"), "<entry>").Count
What about something like this:
var rssFeed = XDocument.Load("http://weblogs.asp.net/scottgu/rss.aspx");
var posts = from item in rssFeed.Descendants("item")
select new
{
Title = (string)item.Element("title"),
Published = (DateTime?)item.Element("pubDate"),
Url = (string)item.Element("link"),
};
Source.
SyndicationFeed.Load(XmlReader.Create("http://weblogs.asp.net/scottgu/rss.aspx")).Items.Count();
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
So I have below code running, where I am calling an Api, which gives me result a Json Array which I am later querying in my code. The response, I get from the api is mostly constant and since it has SOME data, it takes few seconds to get the complete result. I would like to know, if I can store the result coming from api in some way in cache in order to make the whole processing part faster?
EDIT: below code is inside a Foreach loop
foreach (var did in myDeserializedClass)
{
if (did.id == matchedid)
{
url = "https://.../api/information/test";
var response = await Request(Stream.Null, url, "GET");
string message = await response.Content.ReadAsStringAsync();
var allcodes = JsonConvert.DeserializeObject<List<CoCode>>(message);
foreach(var cc in allcodes )
{....// rest of my code
You can absolutely use a memory cache, even Microsoft provide one which if possible also can be place in the api side for quicker lookups
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.memorycache?view=dotnet-plat-ext-6.0
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to create application in WPF wchich will scrape information from webpage
I read link to the page from text box at the top
I want to extract company name from h6
I don't understand that format:"//h2[#class='card__title mdc-typography--headline6']". I could't find documentation abot meaning # [] etc. to create another filters to scrape other data for example phone number from tag.
The #, //, ... represent abbreviated syntax for XPath selectors.
#abc is short for attribute::abc
// is short for /descendant-or-self::node()/
So, in other terms, your current query //h2[#class='card__title mdc-typography--headline6'] represents the action of finding the first descendant- or self-node that has a class attribute of card__title mdc-typography--headline6.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a string input which looks like:
var price = "£1.33(including postage)";
I'd like to take out the first part of the string before ( so that the output of regex would look like this:
"£1.33"
I'm new with Regex so I'm not quite sure how to do this, can someone help me out?
P.S. I thought of doing a substring, but that wouldn't work since price can have more decimals, and can be a larger price, so this option definitely wouldn't work
do you have to use regex?
much easier if you use split
string result = price.Split('(').First();
You don't need Regex for this if you have the same basic format of the "price" just different values.
var result = price.Substring(0, price.IndexOf("("));.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two urls:
http://sp2013/sites/1234
and
http://sp2013/pwa/projectsites/projectdetails.aspx?projuid=1234-123-123-123456-123456
I want to get from the first url the last part (always a number)
1234
and from the second url also the last part (guid)
1234-123-123-123456-123456
How could i achieve this through RegEx or maybe with string operations in C#?
string s = "http://sp2013/sites/1234";
var firstURLlastPart = new Uri(s).Segments.Last();
string s = "http://sp2013/pwa/projectsites/projectdetails.aspx?projuid=1234-123-123-123456-123456";
var secondURLlastPart = s.Split('=').Last();
Just split at '/' and take the last chunk for the first case.
str.Split('/').Last()
Split at '=' and take last chunk for second case
str.Split('=').Last()
(?!\/|\=).[-0-9]+$
It's working for both. But it also accepts if in first example will be number in format like this:
12345-4568
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to scan a portion of the webpage for specific URLs using htmlagilitypack and C#. How can I do it? For example I would like to scan only the links of the ads from this page http://www.olx.in/mobile-phones-cat-831 and not all the links.
It looks like each of the Add links is nested inside a div with a specific class (adListDetails), so one can look for any links inside a div with said class. That would look like this:
var nodes = document.DocumentNode.SelectNodes("//div[class='#adListDetails']//a[#src]");
foreach (var node in nodes)
{
string src = node.Attributes["src"].Value;
}
Learn more XPath from a source like w3schools.