Skip to content

Commit 40450db

Browse files
committed
url: Implement url helper
1 parent f47cfa5 commit 40450db

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

CustomCrawler/CustomCrawler.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Reference Include="System.Drawing" />
9393
<Reference Include="System.IO.Compression" />
9494
<Reference Include="System.IO.Compression.FileSystem" />
95+
<Reference Include="System.Web" />
9596
<Reference Include="System.Xml" />
9697
<Reference Include="Microsoft.CSharp" />
9798
<Reference Include="System.Core" />
@@ -147,6 +148,7 @@
147148
<Compile Include="HtmlCAL.cs" />
148149
<Compile Include="HtmlTree.cs" />
149150
<Compile Include="SeleniumWrapper.cs" />
151+
<Compile Include="URLHelper.cs" />
150152
<Compile Include="Utils.cs" />
151153
<Page Include="CustomCrawler.xaml">
152154
<Generator>MSBuild:Compile</Generator>

CustomCrawler/URLHelper.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***
2+
3+
Copyright (C) 2020. rollrat. All Rights Reserved.
4+
5+
Author: Custom Crawler Developer
6+
7+
***/
8+
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
using System.Web;
15+
16+
namespace CustomCrawler
17+
{
18+
public class URLHelper
19+
{
20+
Uri url;
21+
22+
public URLHelper(string url)
23+
{
24+
this.url = new Uri(url);
25+
}
26+
27+
Dictionary<string, string> buffer;
28+
29+
public Dictionary<string, string> Parameters
30+
{
31+
get
32+
{
33+
if (buffer != null)
34+
return buffer;
35+
var pp = HttpUtility.ParseQueryString(url.Query);
36+
var result = new Dictionary<string, string>();
37+
foreach (var key in pp.AllKeys)
38+
result.Add(key, pp[key]);
39+
return buffer = result;
40+
}
41+
}
42+
43+
public List<string> DiffParams(URLHelper url)
44+
{
45+
var p1 = Parameters;
46+
var p2 = url.Parameters;
47+
48+
return p1.Keys.Intersect(p2.Keys).Where(x => p1[x] != p2[x]).ToList();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)