![]() |
|
[C#] C# Regex for URL Grabbing - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] C# Regex for URL Grabbing (/showthread.php?tid=6014428) |
C# Regex for URL Grabbing - Bruce Banner - Oct 7, 2019 Hi all, I need to grab some URL's from a page source code and am trying to do so using regex. I am not very familiar with regex and have only used it a couple times. Here is the section of the code from which I am trying to grab the links from: Code <script type="application/ld+json">Please note I am parsing an entire page source code(9gag.com/Germany) into a string not just the code above. I would also be fine if I was just able to grab the id in each link such as "aV0qvqn" in the first one. Stack overflow suggested this solution: https://stackoverflow.com/questions/10576686/c-sharp-regex-pattern-to-extract-urls-from-given-string-not-full-html-urls-but but it does not work. This grabs every link in the source code besides the links I need so I am guessing the "\/\/" and other characters are messing it up? Help would be much appreciated on this, thanks! RE: C# Regex for URL Grabbing - gigajew - Oct 7, 2019 Why has nobody suggested decoding the json and getting all the values? Using NewtonSoft.Json library available in nuget package: ![]() Also, if you still insist on using Regular Expression to do this, check out this: https://rubular.com/r/iW6y82MjNLRV1y or this https://rubular.com/r/bfwLyXglZwUzzV RE: C# Regex for URL Grabbing - Bruce Banner - Oct 7, 2019 (Oct 7, 2019 08:16 PM)gigajew Wrote: Why has nobody suggested decoding the json and getting all the values? I was literally just checking out this package as I saw you post this lol! Thanks for the response I am working on it now. RE: C# Regex for URL Grabbing - Fhack - Oct 8, 2019 Use htmlagilitypack and extract all <a href /> élément ! RE: C# Regex for URL Grabbing - 0xDEAD10CC - Oct 8, 2019 (Oct 8, 2019 06:59 AM)Fhack Wrote: Use htmlagilitypack and extract all <a href /> élément ! URL's don't have to always exist in <a> elements or "href" attributes. RE: C# Regex for URL Grabbing - Bruce Banner - Oct 8, 2019 Got it working with gigajew's post. Closing this thread. Thanks everyone for helping out. |