C# WebClient.DownloadString() Get specific part? [closed] - c#

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 6 years ago.
Improve this question
I want to download a specif string from website but I am not sure how I achieve it the best way.
Right now I do it like this:
using (WebClient webClient = new WebClient())
{
string htmlString = webClient.DownloadString(url);
string encoding = WebUtility.UrlDecode(htmlString);
Console.WriteLine(encoding);
}
However, this returns the whole webpage as a string, can I somehow only download a specific part of the URL?

If the webserver support byte serving (Accept-Ranges header) then you can access a part of the document.
https://en.wikipedia.org/wiki/Byte_serving
https://msdn.microsoft.com/library/7fy67z6d(v=vs.100).aspx
https://blogs.msdn.microsoft.com/webdev/2012/11/23/asp-net-web-api-and-http-byte-range-support/

Related

C# store/load guid list in a file [closed]

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 1 year ago.
Improve this question
Is there a posiblity to store and load a guid list in a file?
List<Guid> targetFaceIds = new List<Guid>();
foreach (var imageFileName in targetImageFileNames)
{
List<DetectedFace> detectedFaces = await DetectFaceRecognize(client, _imagePath + imageFileName, recognitionModel);
targetFaceIds.Add(detectedFaces[0].FaceId.Value);
}
In my programm I want to store 'targetFaceIds' in a file is that possible and how can I load it back form the file in my programm.
In my 'targetFaceIds' is this:
You can use guid.ToString to convert it to a string and Guid.Parse to parse it back to a Guid:
File.WriteAllLines(path, targetFaceIds.Select(g => g.ToString())); // write
targetFaceIds = File.ReadAllLines(path).Select(Guid.Parse).ToList(); // read

Below code are written in mvc controller, can anyone explain this? [closed]

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
Can Anyone explain the use of the below lines in .net MVC
string apiResponse = await response.Content.ReadAsStringAsync();
_hdfcData = JsonConvert.DeserializeObject<HDFCData>(apiResponse);
string apiResponse = await response.Content.ReadAsStringAsync();
get http response message and serialize it to string
_hdfcData = JsonConvert.DeserializeObject<HDFCData>(apiResponse);
deserialize the string to HDFCData type

How to use HtmlAgilityPack to receive JSON data from script [closed]

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
My question is about the following html: https://pastebin.com/qT97gBh5
I download the HTML Site by using
var url = "https://www.twitch.tv/monstercat";
var web = new HtmlWeb();
var doc = web.Load(url);
Now the only thing that interests me is the JSON Data off the following section.
<script type="application/ld+json">[{"#context":"http://schema.org","#type":"VideoObject","thumbnailUrl":["https://static-cdn.jtvnw.net/previews-ttv/live_user_monstercat-{width}x{height}.jpg"],"embedUrl":"https://player.twitch.tv/?channel=monstercat&player=facebook&autoplay=true","name":"Monstercat - Twitch","description":"Non Stop Music - Monstercat Radio 🎶","videoQuality":"1080p","publication":{"#type":"BroadcastEvent","isLiveBroadcast":true,"startDate":"03/29/2020 19:04:06"},"author":{"#type":"Person","name":"Monstercat","url":"https://www.twitch.tv/monstercat"},"uploadDate":"03/29/2020 19:04:06"}]</script>
How would i use HtmlAgilityPack to use the xpath
/html/head/script[2] to receive the JSON Data?
you can search about agility pack in c# and after that use agility to get this X path
/html/head/script[2]
now you have a json string. convert json to property with newtonsoft(add this package with Nuget).congratulation so you can read description in your class.

Get the Special Character from URL [closed]

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
Url is like That:
http://localhost:620251/Default.aspx/?group=Bkgbdsconsumer & Retailmailinglist
Want the group value on cs page:
Bkgbdsconsumer & Retailmailinglist
I ma doing this:
string group= HttpUtility.UrlEncode(Request.QueryString["group"]);
EDIT:
Ok, as I thought, there is no space before and after & in your URL.
Also port number is too big 620251 (max is 65535 as I think).
// 'fixed' port number
string url = #"http://localhost:12345/Default.aspx/?group=Bkgbdsconsumer&Retailmailinglist";
Uri myUri = new Uri (url);
var groupValue = HttpUtility.ParseQueryString (myUri.Query)["group"];
string[] allKeysWithoutValue = HttpUtility.ParseQueryString (myUri.Query).GetValues (null);
Now allKeysWithoutValue is an array with one element Retailmailinglist.

scanning a portion of webapage using htmlagilitypack and C# [closed]

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.

Categories

Resources