Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I need a regex that scans the page for magnet links and gets the magnet links in matches collection...

What I have tried:

private void downloadPage(string pageLink)
        {
            string s = (new System.Net.WebClient()).DownloadString(pageLink);

            while (!string.IsNullOrWhiteSpace(s))
            {
                if (s.StartsWith(@"magnet:?xt=urn:btih:"))
                {
                    for (int d = 20; d < s.Length; d++)
                    {
                        if (s[d] == '"')
                        {
                            System.Diagnostics.Process.Start(s.Substring(0, d));
                            s = s.Substring(d);
                            break;
                        }
                    }
                }
                else
                {
                    s = s.Substring(1);
                }
            }
        }
Posted
Updated 14-Sep-17 11:18am

This link extracts URLs from a page. It should not be that difficult to modify it to do what you want: Extracting all links from a HTML page[^]
 
Share this answer
 
Comments
Graeme_Grant 14-Sep-17 16:43pm    
You are welcome. A quick Google Search found that link for you: How to get magnet links from a page using regex[^]
john1990_1 14-Sep-17 17:08pm    
Thx a lot
void downloadPage(string pageLink)
        {
            foreach (Match m in new Regex("magnet:\\?xt=urn:btih:.*?\"").Matches((new System.Net.WebClient()).DownloadString(pageLink)))
            {
                System.Diagnostics.Process.Start(m.Value.Remove(m.Value.Length-1));
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900