├── .dockerignore ├── .github ├── FUNDING.yml └── workflows │ └── publish_docker.yml ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Cli ├── Cli.csproj └── Program.cs ├── Http ├── .vscode │ └── settings.sample.json ├── code.http ├── crawling.http ├── http-client.env.json └── source.http ├── LICENSE ├── README.md ├── Server ├── Code │ └── ResultCode.cs ├── Controllers │ ├── CodeController.cs │ ├── CrawlingController.cs │ ├── NotificationController.cs │ └── SourceController.cs ├── Dockerfile ├── Program.cs ├── Protocols │ ├── Common │ │ ├── CrawlingData.cs │ │ ├── Header.cs │ │ ├── Notification.cs │ │ ├── NotificationCreate.cs │ │ └── Source.cs │ ├── Request │ │ ├── Crawling.cs │ │ ├── CrawlingList.cs │ │ ├── NotificationCreate.cs │ │ ├── NotificationMulti.cs │ │ ├── NotificationUpdate.cs │ │ ├── Source.cs │ │ └── SourceMulti.cs │ └── Response │ │ ├── CodeList.cs │ │ ├── Crawling.cs │ │ ├── CrawlingList.cs │ │ ├── Notification.cs │ │ ├── NotificationMulti.cs │ │ ├── Pagable.cs │ │ ├── Source.cs │ │ └── SourceMulti.cs ├── Server.csproj ├── Services │ ├── CrawlingLoopingService.cs │ ├── CrawlingService.cs │ ├── NotificationService.cs │ └── SourceService.cs ├── Startup.cs ├── appsettings.Production.json.sample ├── appsettings.json ├── serilog.json └── serilog.json.sample ├── UnitTest ├── UnitTest.csproj └── WebCrawler.cs ├── WebCrawler ├── Code │ └── CrawlingType.cs ├── Crawler │ ├── ClienCrawler.cs │ ├── CrawlerBase.cs │ ├── DcInsideCrawler.cs │ ├── FmkoreaCrawler.cs │ ├── HumorUnivCrawler.cs │ ├── InvenNewsCrawler.cs │ ├── ItcmCrawler.cs │ ├── PpomppuCrawler.cs │ ├── RuliwebCrawler.cs │ ├── SlrclubCrawler.cs │ ├── SlrclubPageInfoCrawler.cs │ └── TodayhumorCrawler.cs ├── Models │ ├── CrawlingData.cs │ └── Source.cs └── WebCrawler.csproj ├── nuget.config ├── sample1.png └── web-crawler.sln /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md 26 | 27 | # development, production settings 28 | appsettings.Production.json 29 | appsettings.Development.json -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: elky84 2 | -------------------------------------------------------------------------------- /.github/workflows/publish_docker.yml: -------------------------------------------------------------------------------- 1 | name: Publish Docker image 2 | 3 | on: 4 | push: 5 | branches: master 6 | 7 | jobs: 8 | push_to_registry: 9 | name: Push Docker image 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out the repo 13 | uses: actions/checkout@v3 14 | 15 | - name: Set up Docker Buildx 16 | uses: docker/setup-buildx-action@v2 17 | 18 | - uses: actions/setup-dotnet@v4 19 | with: 20 | source-url: https://nuget.pkg.github.com/elky84/index.json 21 | dotnet-version: '9.x.x' 22 | env: 23 | NUGET_AUTH_TOKEN: ${{secrets.DOCKER_GITHUB_PASSWORD}} 24 | 25 | - name: Login to GitHub Container Registry 26 | uses: docker/login-action@v2 27 | with: 28 | registry: ghcr.io 29 | username: ${{ github.repository_owner }} 30 | password: ${{ secrets.DOCKER_GITHUB_PASSWORD }} 31 | 32 | - name: Build and push Docker image 33 | uses: docker/build-push-action@v3 34 | with: 35 | context: . 36 | file: ./Server/Dockerfile 37 | push: true 38 | tags: ghcr.io/elky84/web-crawler:latest -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | # settings json 353 | appsettings.Production.json 354 | appsettings.Development.json 355 | 356 | # local config 357 | deploy_*.bat 358 | 359 | # properties 360 | Properties/ 361 | 362 | # vscode rest client 363 | notification.http 364 | http/.vscode/settings.json 365 | 366 | # rider 367 | .idea/ -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": ".NET Core Launch (console)", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "cli_build", 9 | "program": "${workspaceFolder}/Cli/bin/Debug/net6.0/Cli.dll", 10 | "args": [], 11 | "cwd": "${workspaceFolder}", 12 | "stopAtEntry": false, 13 | "console": "internalConsole", 14 | "logging": { 15 | "moduleLoad": false 16 | } 17 | }, 18 | 19 | { 20 | // Use IntelliSense to find out which attributes exist for C# debugging 21 | // Use hover for the description of the existing attributes 22 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 23 | "name": ".NET Core Launch (web)", 24 | "type": "coreclr", 25 | "request": "launch", 26 | "preLaunchTask": "server_build", 27 | // If you have changed target frameworks, make sure to update the program path. 28 | "program": "${workspaceFolder}/Server/bin/Debug/net6.0/Server.dll", 29 | "args": [], 30 | "cwd": "${workspaceFolder}/Server", 31 | "stopAtEntry": false, 32 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser 33 | "serverReadyAction": { 34 | "action": "openExternally", 35 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 36 | }, 37 | "env": { 38 | "ASPNETCORE_ENVIRONMENT": "Development" 39 | }, 40 | "sourceFileMap": { 41 | "/Views": "${workspaceFolder}/Views" 42 | }, 43 | "logging": { 44 | "moduleLoad": false 45 | } 46 | }, 47 | { 48 | "name": ".NET Core Attach", 49 | "type": "coreclr", 50 | "request": "attach" 51 | } 52 | ] 53 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "server_build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Server/Server.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "cli_build", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "build", 22 | "${workspaceFolder}/Cli/Cli.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "publish", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "publish", 34 | "${workspaceFolder}/Server/Server.csproj", 35 | "/property:GenerateFullPaths=true", 36 | "/consoleloggerparameters:NoSummary" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | }, 40 | { 41 | "label": "watch", 42 | "command": "dotnet", 43 | "type": "process", 44 | "args": [ 45 | "watch", 46 | "run", 47 | "--project", 48 | "${workspaceFolder}/Server/Server.csproj" 49 | ], 50 | "problemMatcher": "$msCompile" 51 | } 52 | ] 53 | } -------------------------------------------------------------------------------- /Cli/Cli.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | cli 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Cli/Program.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Driver; 2 | using Serilog; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using WebCrawler.Code; 6 | using WebCrawler.Crawler; 7 | 8 | namespace Cli 9 | { 10 | internal static class Program 11 | { 12 | private static async Task Main(string[] args) 13 | { 14 | Log.Logger = new LoggerConfiguration() 15 | .MinimumLevel.Warning() 16 | .WriteTo.Console() 17 | .CreateLogger(); 18 | 19 | Log.Warning("starting up!"); 20 | 21 | var client = new MongoClient("mongodb://localhost:27017/?maxPoolSize=200"); 22 | var database = client.GetDatabase("cli-web-crawler"); 23 | 24 | await new DcInsideCrawler(null, database, new WebCrawler.Models.Source 25 | { 26 | Type = CrawlingType.DcInside, 27 | BoardId = "mgallery/board/lists/?id=pathofexile&sort_type=N&search_head=10", 28 | Name = "POE1 갤러리/빌드" 29 | }).RunAsync(); 30 | 31 | await new RuliwebCrawler(null, database, new WebCrawler.Models.Source 32 | { 33 | Type = CrawlingType.Ruliweb, 34 | BoardId = "market/board/1020", 35 | Name = "핫딜게시판" 36 | }).RunAsync(); 37 | 38 | await new RuliwebCrawler(null, database, new WebCrawler.Models.Source 39 | { 40 | Type = CrawlingType.Ruliweb, 41 | BoardId = "best/selection", 42 | Name = "베스트" 43 | }).RunAsync(); 44 | 45 | await new RuliwebCrawler(null, database, new WebCrawler.Models.Source 46 | { 47 | Type = CrawlingType.Ruliweb, 48 | BoardId = "best", 49 | Name = "유머베스트" 50 | }).RunAsync(); 51 | 52 | await new DcInsideCrawler(null, database, new WebCrawler.Models.Source 53 | { 54 | Type = CrawlingType.DcInside, 55 | BoardId = "mgallery/board/lists/?id=pathofexile&exception_mode=recommend", 56 | Name = "POE1 갤러리" 57 | }).RunAsync(); 58 | 59 | await new RuliwebCrawler(null, database, new WebCrawler.Models.Source 60 | { 61 | Type = CrawlingType.Ruliweb, 62 | BoardId = "market/board/1003", 63 | Name = "콘솔뉴스" 64 | }).RunAsync(); 65 | 66 | await new PpomppuCrawler(null, database, new WebCrawler.Models.Source 67 | { 68 | Type = CrawlingType.Ppomppu, 69 | BoardId = "freeboard", 70 | Name = "자유게시판" 71 | }).RunAsync(); 72 | 73 | await new PpomppuCrawler(null, database, new WebCrawler.Models.Source 74 | { 75 | Type = CrawlingType.Ppomppu, 76 | BoardId = "ppomppu", 77 | Name = "뽐뿌핫딜" 78 | }).RunAsync(); 79 | 80 | await new TodayhumorCrawler(null, database, new WebCrawler.Models.Source 81 | { 82 | Type = CrawlingType.TodayHumor, 83 | BoardId = "bestofbest", 84 | Name = "베오베" 85 | }).RunAsync(); 86 | 87 | await new SlrclubCrawler(null, database, new WebCrawler.Models.Source 88 | { 89 | Type = CrawlingType.SlrClub, 90 | BoardId = "free", 91 | Name = "자유게시판" 92 | }).RunAsync(); 93 | 94 | await new FmkoreaCrawler(null, database, new WebCrawler.Models.Source 95 | { 96 | Type = CrawlingType.FmKorea, 97 | BoardId = "football_news", 98 | Name = "축구 뉴스" 99 | }).RunAsync(); 100 | 101 | await new ClienCrawler(null, database, new WebCrawler.Models.Source 102 | { 103 | Type = CrawlingType.Clien, 104 | BoardId = "sold", 105 | Name = "회원중고장터" 106 | }).RunAsync(); 107 | 108 | await new FmkoreaCrawler(null, database, new WebCrawler.Models.Source 109 | { 110 | Type = CrawlingType.FmKorea, 111 | BoardId = "lol&sort_index=pop", 112 | Name = "펨코 롤" 113 | }).RunAsync(); 114 | 115 | await new ItcmCrawler(null, database, new WebCrawler.Models.Source 116 | { 117 | Type = CrawlingType.Itcm, 118 | BoardId = "game_news", 119 | Name = "핫딜" 120 | }).RunAsync(); 121 | 122 | await new ClienCrawler(null, database, new WebCrawler.Models.Source 123 | { 124 | Type = CrawlingType.Clien, 125 | BoardId = "jirum", 126 | Name = "지름" 127 | }).RunAsync(); 128 | 129 | await new FmkoreaCrawler(null, database, new WebCrawler.Models.Source 130 | { 131 | Type = CrawlingType.FmKorea, 132 | BoardId = "hotdeal", 133 | Name = "펨코핫딜" 134 | }).RunAsync(); 135 | 136 | await new FmkoreaCrawler(null, database, new WebCrawler.Models.Source 137 | { 138 | Type = CrawlingType.FmKorea, 139 | BoardId = "best", 140 | Name = "포텐터짐" 141 | }).RunAsync(); 142 | 143 | await new HumorUnivCrawler(null, database, new WebCrawler.Models.Source 144 | { 145 | Type = CrawlingType.HumorUniv, 146 | BoardId = "pick", 147 | Name = "인기자료" 148 | }).RunAsync(); 149 | 150 | await new InvenNewsCrawler(null, database, new WebCrawler.Models.Source 151 | { 152 | Type = CrawlingType.InvenNews, 153 | BoardId = "site=lol", 154 | Name = "인벤 LOL 뉴스" 155 | }).RunAsync(); 156 | } 157 | } 158 | } -------------------------------------------------------------------------------- /Http/.vscode/settings.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "rest-client.environmentVariables": { 3 | "$shared": { 4 | }, 5 | "local": { 6 | "host": "http://localhost:5000" 7 | }, 8 | "cloudtype": { 9 | "host": "" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Http/code.http: -------------------------------------------------------------------------------- 1 | ### Code CrawlingType 2 | 3 | GET {{host}}/Code/CrawlingType 4 | -------------------------------------------------------------------------------- /Http/crawling.http: -------------------------------------------------------------------------------- 1 | ### Crawling all 2 | 3 | GET {{host}}/Crawling?offset=0&limit=10&asc=true 4 | 5 | ### Crawling all 6 | 7 | POST {{host}}/Crawling 8 | Content-Type: application/json 9 | 10 | { 11 | "All":true 12 | } 13 | 14 | ### 15 | 16 | GET {{host}}/Crawling?offset=0&limit=10&asc=true 17 | 18 | -------------------------------------------------------------------------------- /Http/http-client.env.json: -------------------------------------------------------------------------------- 1 | { 2 | "dev": { 3 | "host": "http://192.168.0.60:20082" 4 | }, 5 | "local": { 6 | "host": "http://localhost:20082" 7 | } 8 | } -------------------------------------------------------------------------------- /Http/source.http: -------------------------------------------------------------------------------- 1 | ### Source Get 2 | 3 | GET {{host}}/Source 4 | 5 | 6 | ### Source Create Multi 7 | 8 | POST {{host}}/Source/Multi 9 | Content-Type: application/json 10 | 11 | { 12 | "Datas": [ 13 | { 14 | "Type": "Ruliweb", 15 | "BoardId": "best", 16 | "Name": "유머 베스트", 17 | "Switch": true, 18 | "Interval": 1000 19 | }, 20 | { 21 | "Type": "Ruliweb", 22 | "BoardId": "market/board/1020", 23 | "Name": "핫딜게시판", 24 | "Switch": true, 25 | "Interval": 1000 26 | }, 27 | { 28 | "Type": "Ruliweb", 29 | "BoardId": "market/board/1001", 30 | "Name": "콘솔뉴스", 31 | "Switch": true, 32 | "Interval": 1000 33 | }, 34 | { 35 | "Type": "Ruliweb", 36 | "BoardId": "market/board/1003", 37 | "Name": "PC뉴스", 38 | "Switch": true, 39 | "Interval": 1000 40 | }, 41 | { 42 | "Type": "Ruliweb", 43 | "BoardId": "sports/board/300276", 44 | "Name": "스포츠", 45 | "Switch": true, 46 | "Interval": 1000 47 | }, 48 | { 49 | "Type": "Ruliweb", 50 | "BoardId": "best/selection", 51 | "Name": "많이 본 글", 52 | "Switch": true, 53 | "Interval": 1000 54 | }, 55 | { 56 | "Type": "Ppomppu", 57 | "BoardId": "ppomppu", 58 | "Name": "뽐뿌핫딜", 59 | "Switch": true, 60 | "Interval": 1000 61 | }, 62 | { 63 | "Type": "Ppomppu", 64 | "BoardId": "freeboard", 65 | "Name": "뽐뿌자게", 66 | "Switch": true, 67 | "Interval": 1000 68 | }, 69 | { 70 | "Type": "TodayHumor", 71 | "BoardId": "bestofbest", 72 | "Name": "베오베", 73 | "Switch": true, 74 | "Interval": 1000 75 | }, 76 | { 77 | "Type": "SlrClub", 78 | "BoardId": "free", 79 | "Name": "자유게시판", 80 | "Switch": true, 81 | "Interval": 1000 82 | }, 83 | { 84 | "Type": "FmKorea", 85 | "BoardId": "football_news", 86 | "Name": "축구 뉴스", 87 | "Interval": 60000, 88 | "Switch": true 89 | }, 90 | { 91 | "Type": "Clien", 92 | "BoardId": "sold", 93 | "Name": "회원중고장터", 94 | "Switch": true, 95 | "Interval": 1000 96 | }, 97 | { 98 | "Type": "Clien", 99 | "BoardId": "park", 100 | "Name": "모두의공원", 101 | "Switch": true, 102 | "Interval": 1000 103 | }, 104 | { 105 | "Type": "InvenNews", 106 | "BoardId": "site=lol", 107 | "Name": "인벤 LOL 뉴스", 108 | "Switch": true, 109 | "Interval": 1000 110 | }, 111 | { 112 | "Type": "FmKorea", 113 | "BoardId": "best", 114 | "Name": "포텐터짐", 115 | "Interval": 60000, 116 | "Switch": true 117 | }, 118 | { 119 | "Type": "FmKorea", 120 | "BoardId": "hotdeal", 121 | "Name": "핫딜", 122 | "Interval": 60000, 123 | "Switch": true 124 | }, 125 | { 126 | "Type": "HumorUniv", 127 | "BoardId": "pick", 128 | "Name": "인기자료", 129 | "Switch": true, 130 | "Interval": 1000 131 | }, 132 | { 133 | "Type": "Clien", 134 | "BoardId": "jirum", 135 | "Name": "알뜰구매", 136 | "Switch": true, 137 | "Interval": 1000 138 | }, 139 | { 140 | "Type": "Itcm", 141 | "BoardId": "game_news", 142 | "Name": "핫딜", 143 | "Switch": true, 144 | "Interval": 1000 145 | }, 146 | { 147 | "Type": "FmKorea", 148 | "BoardId": "lol&sort_index=pop", 149 | "Name": "펨코 롤", 150 | "Switch": true, 151 | "Interval": 60000 152 | }, 153 | { 154 | "Type": "DcInside", 155 | "BoardId": "mgallery/board/lists/?id=pathofexile&exception_mode=recommend", 156 | "Name": "POE1 갤러리", 157 | "Switch": true, 158 | "Interval": 1000 159 | }, 160 | { 161 | "Type": "DcInside", 162 | "BoardId": "mgallery/board/lists/?id=poe2&sort_type=N&exception_mode=recommend&search_head=10", 163 | "Name": "POE2 갤러리", 164 | "Switch": true, 165 | "Interval": 1000 166 | }, 167 | { 168 | "Type": "DcInside", 169 | "BoardId": "mgallery/board/lists/?id=pathofexile&sort_type=N&search_head=10", 170 | "Name": "POE1 갤러리/P1빌드", 171 | "Switch": true, 172 | "Interval": 1000 173 | } 174 | ] 175 | } 176 | 177 | ### Source Create 178 | 179 | POST {{host}}/Source 180 | Content-Type: application/json 181 | 182 | { 183 | "Data": { 184 | "Type": "DcInside", 185 | "BoardId": "mgallery/board/lists/?id=pathofexile&sort_type=N&search_head=10", 186 | "Name": "POE1 갤러리/P1빌드", 187 | "Switch": true, 188 | "Interval": 1000 189 | } 190 | } 191 | 192 | 193 | ### Source Get 194 | 195 | GET {{host}}/Source/5f5a25cc6e6fbaf1a5e7ccca 196 | 197 | ### Source Update 198 | 199 | PUT {{host}}/Source/5f5a25cc6e6fbaf1a5e7ccca 200 | Content-Type: application/json 201 | 202 | { 203 | "Data": { 204 | "Type":"Ruliweb", 205 | "BoardId": "1020", 206 | "Name": "핫딜게시판", 207 | "Interval": 1000 208 | } 209 | } 210 | 211 | ### Source Delete 212 | 213 | DELETE {{host}}/Source/5f5a25cc6e6fbaf1a5e7ccca 214 | 215 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Website](https://img.shields.io/website-up-down-green-red/http/shields.io.svg?label=elky-essay)](https://elky84.github.io) 2 | ![Made with](https://img.shields.io/badge/made%20with-.NET8-brightgreen.svg) 3 | ![Made with](https://img.shields.io/badge/made%20with-JavaScript-blue.svg) 4 | ![Made with](https://img.shields.io/badge/made%20with-MongoDB-red.svg) 5 | 6 | [![Publish Docker image](https://github.com/elky84/web-crawler/actions/workflows/publish_docker.yml/badge.svg)](https://github.com/elky84/web-crawler/actions/workflows/publish_docker.yml) 7 | 8 | ![GitHub forks](https://img.shields.io/github/forks/elky84/web-crawler.svg?style=social&label=Fork) 9 | ![GitHub stars](https://img.shields.io/github/stars/elky84/web-crawler.svg?style=social&label=Stars) 10 | ![GitHub watchers](https://img.shields.io/github/watchers/elky84/web-crawler.svg?style=social&label=Watch) 11 | ![GitHub followers](https://img.shields.io/github/followers/elky84.svg?style=social&label=Follow) 12 | 13 | ![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg) 14 | ![GitHub repo size in bytes](https://img.shields.io/github/repo-size/elky84/web-crawler.svg) 15 | ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/elky84/web-crawler.svg) 16 | 17 | # web-crawler 18 | 19 | * .NET 9, ASP NET CORE 를 기반으로 작성되었습니다. 20 | * 크롤링 대상은 Source로 등록되어야 합니다. [예시](https://github.com/elky84/web-crawler/blob/master/Http/source.http) 21 | * Source로 등록된 게시판들은 테스트를 거쳐 크롤링 됨을 확인한 사이트와 게시판 들이지만, 규격이 달라져 추가적인 예외처리가 필요할 수 있습니다. 22 | * 알림은 Discord, Slack을 지원합니다. Notification 데이터를, Source와 매핑 시켜서 해당 Source에 새 데이터가 갱신되면 알림이 날라오게 되어있습니다. 23 | * DB로는 mongoDB를 사용합니다. 24 | * API는 swagger를 통해 확인하셔도 좋지만, http 폴더 안에 예제가 포함되어있습니다. 25 | 26 | ## 사용법 27 | * MongoDB 설정 (Server 프로젝트) 28 | * `MONGODB_CONNECTION` 환경 변수에 `MONGODB 커넥션 문자열` 입력 29 | * 선택적 MongoDB 데이터베이스 30 | * 기본 값은 `rss-feed-crawler` 31 | * `MONGODB_DATABASE` 환경 변수 사용시 override 32 | * 환경 변수 미사용시, appSettings.[환경].json 파일에 있는 값을 사용합니다. (환경에 맞는 파일 미제공시, appSettings.json 의 값을 그대로 이용) 33 | * Crawling 처리를 하는 스레드에 제한 기능 34 | * `THREAD_LIMIT` 환경 변수에 제한 스레드 수를 입력 35 | 36 | ## 현재 지원중인 크롤링 대상 (사이트) 37 | * Clien 38 | * FmKorea 39 | * 웃긴대학 (HumorUniv) 40 | * Itcm 41 | * 인벤 뉴스 (InvenNews) 42 | * Ppomppu 43 | * Ruliweb 44 | * Slrclub 45 | * 오유 (TodayHumor) 46 | * DC Inside 47 | 48 | ## 각종 API 예시 49 | * VS Code의 RestClient Plugin의 .http 파일용으로 작성 50 | * 51 | * .http 파일 경로 52 | * 53 | * 해당 경로 아래에 .vscode 폴더에 settings.json.sample을 복사해, settings.json으로 변경하면, VSCode로 해당 기능 오픈시 환경에 맞는 URI로 호출 가능하게 됨 54 | * 55 | * Swagger로 확인해도 무방함 56 | * 57 | 58 | ## Notification.http 예시 59 | 60 | ``` 61 | ### VS Code의 RestClient Plugin의 .http 파일용 서식입니다 62 | 63 | ### Notification Create Multi Discord 64 | 65 | POST {{host}}/Notification/Multi 66 | Content-Type: application/json 67 | 68 | { 69 | "Datas": [{ 70 | "Type": "Discord", 71 | "Name": "핫딜", 72 | "IconUrl": "https://lh3.googleusercontent.com/OwN24ti7VzhNXGWVw4RQD-dfkGEf-fnFb7yz--knAwPoxR9VSXpGb3UoOYJNyDIKiQ=s180", 73 | "HookUrl": "", 74 | "CrawlingType": "Ruliweb", 75 | "BoardName": "핫딜게시판" 76 | }, 77 | { 78 | "Type": "Discord", 79 | "Name": "콘솔뉴스", 80 | "IconUrl": "https://lh3.googleusercontent.com/OwN24ti7VzhNXGWVw4RQD-dfkGEf-fnFb7yz--knAwPoxR9VSXpGb3UoOYJNyDIKiQ=s180", 81 | "HookUrl": "", 82 | "CrawlingType": "Ruliweb", 83 | "BoardName": "콘솔뉴스" 84 | }, 85 | { 86 | "Type": "Discord", 87 | "Name": "PC뉴스", 88 | "IconUrl": "https://lh3.googleusercontent.com/OwN24ti7VzhNXGWVw4RQD-dfkGEf-fnFb7yz--knAwPoxR9VSXpGb3UoOYJNyDIKiQ=s180", 89 | "HookUrl": "", 90 | "CrawlingType": "Ruliweb", 91 | "BoardName": "PC뉴스" 92 | }, 93 | { 94 | "Type": "Discord", 95 | "Name": "많이 본 글", 96 | "IconUrl": "https://lh3.googleusercontent.com/OwN24ti7VzhNXGWVw4RQD-dfkGEf-fnFb7yz--knAwPoxR9VSXpGb3UoOYJNyDIKiQ=s180", 97 | "HookUrl": "", 98 | "CrawlingType": "Ruliweb", 99 | "BoardName": "많이 본 글", 100 | "FilterDayOfWeeks": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], 101 | "FilterStartTime": "09:00:00", 102 | "FilterEndTime": "19:00:00" 103 | }, 104 | { 105 | "Type": "Discord", 106 | "Name": "베오베", 107 | "IconUrl": "https://apprecs.org/ios/images/app-icons/256/6f/664550767.jpg", 108 | "HookUrl": "", 109 | "CrawlingType": "TodayHumor", 110 | "BoardName": "베오베", 111 | "FilterDayOfWeeks": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], 112 | "FilterStartTime": "09:00:00", 113 | "FilterEndTime": "19:00:00" 114 | }, 115 | { 116 | "Type": "Discord", 117 | "Name": "축구 뉴스", 118 | "IconUrl": "https://media.cdnandroid.com/item_images/1047984/imagen-i-i-i-ee-i-i-i-0thumb.jpeg", 119 | "HookUrl": "", 120 | "CrawlingType": "FmKorea", 121 | "BoardName": "축구 뉴스", 122 | "Keyword": "토트넘" 123 | }, 124 | { 125 | "Type": "Discord", 126 | "Name": "LOL 리포터 뉴스", 127 | "IconUrl": "https://lh3.googleusercontent.com/Hc4D74YO7FYttrPCm5MuDm91NLblaaunJ6Y38WCg9mABUJfobgU_vXy1tjX668bI6xs=s180-rw", 128 | "HookUrl": "", 129 | "CrawlingType": "InvenNews", 130 | "BoardName": "인벤 LOL 뉴스" 131 | }, 132 | { 133 | "Type": "Discord", 134 | "Name": "펨코핫딜", 135 | "IconUrl": "https://media.cdnandroid.com/item_images/1047984/imagen-i-i-i-ee-i-i-i-0thumb.jpeg", 136 | "HookUrl": "", 137 | "CrawlingType": "FmKorea", 138 | "BoardName": "핫딜" 139 | }, 140 | { 141 | "Type": "Discord", 142 | "Name": "포텐터짐", 143 | "IconUrl": "https://media.cdnandroid.com/item_images/1047984/imagen-i-i-i-ee-i-i-i-0thumb.jpeg", 144 | "HookUrl": "", 145 | "CrawlingType": "FmKorea", 146 | "BoardName": "포텐터짐", 147 | "Keyword": "LOL|LCK|DRX|손흥민", 148 | "FilterDayOfWeeks": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], 149 | "FilterStartTime": "09:00:00", 150 | "FilterEndTime": "19:00:00" 151 | }, 152 | { 153 | "Type": "Discord", 154 | "Name": "인기자료", 155 | "IconUrl": "http://down.humoruniv.com/hwiparambbs/data/pdswait/a_4883065431_b9afd56add3ad86ccc10cde95a0d8c0cc57ead30.png", 156 | "HookUrl": "", 157 | "CrawlingType": "HumorUniv", 158 | "BoardName": "인기자료", 159 | "FilterDayOfWeeks": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], 160 | "FilterStartTime": "09:00:00", 161 | "FilterEndTime": "19:00:00" 162 | }, 163 | { 164 | "Type": "Discord", 165 | "Name": "알뜰구매", 166 | "IconUrl": "https://cdn.clien.net/web/api/file/F01/2581830/94f801b57da24373a43.PNG", 167 | "HookUrl": "", 168 | "CrawlingType": "Clien", 169 | "BoardName": "알뜰구매" 170 | }, 171 | { 172 | "Type": "Discord", 173 | "Name": "핫딜", 174 | "IconUrl": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/6b/6b9915f60cb45d4df113cd8f36387ba1de8ce601_full.jpg", 175 | "HookUrl": "", 176 | "CrawlingType": "Itcm", 177 | "BoardName": "핫딜" 178 | } 179 | ] 180 | } 181 | ``` 182 | 183 | ## Discord Alert Sample 184 | 185 | ![sample1](sample1.png) -------------------------------------------------------------------------------- /Server/Code/ResultCode.cs: -------------------------------------------------------------------------------- 1 | namespace Server.Code 2 | { 3 | public class ResultCode : EzAspDotNet.Protocols.Code.ResultCode 4 | { 5 | public ResultCode(int id, string name) : base(id, name) 6 | { 7 | } 8 | 9 | 10 | public readonly static ResultCode UsingSourceId = new(10000, "UsingSourceId"); 11 | public readonly static ResultCode UsingRssId = new(10001, "UsingRssId"); 12 | public readonly static ResultCode UsingNotificationId = new(10002, "UsingNotificationId"); 13 | public readonly static ResultCode NotFoundSource = new(10003, "NotFoundSource"); 14 | public readonly static ResultCode CreateFailedSource = new(10004, "CreateFailedSource"); 15 | public readonly static ResultCode InvalidRequest = new(10005, "InvalidRequest"); 16 | public readonly static ResultCode CreateFailedNotification = new(10006, "CreateFailedNotification"); 17 | 18 | public readonly static ResultCode NotFoundData = new(10010, "NotFoundData"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Server/Controllers/CodeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using System.Linq; 4 | using WebCrawler.Code; 5 | using EnumExtend; 6 | 7 | namespace Server.Controllers 8 | { 9 | [ApiController] 10 | [Route("[controller]")] 11 | public class CodeController : ControllerBase 12 | { 13 | private readonly ILogger _logger; 14 | 15 | public CodeController(ILogger logger) 16 | { 17 | _logger = logger; 18 | } 19 | 20 | [HttpGet("CrawlingType")] 21 | public Protocols.Response.CodeList Get() 22 | { 23 | return new Protocols.Response.CodeList 24 | { 25 | Datas = TypesUtil.ToEnumerable() 26 | .ToList() 27 | .ConvertAll(x => x.ToString()) 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Server/Controllers/CrawlingController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Server.Services; 4 | using System.Threading.Tasks; 5 | 6 | namespace Server.Controllers 7 | { 8 | [ApiController] 9 | [Route("[controller]")] 10 | public class CrawlingController : ControllerBase 11 | { 12 | private readonly ILogger _logger; 13 | 14 | private readonly CrawlingService _crawlingService; 15 | 16 | public CrawlingController(ILogger logger, CrawlingService crawlingService) 17 | { 18 | _logger = logger; 19 | _crawlingService = crawlingService; 20 | } 21 | 22 | [HttpGet] 23 | public async Task Get([FromQuery] Protocols.Request.CrawlingList crawlingList) 24 | { 25 | return await _crawlingService.Get(crawlingList); 26 | } 27 | 28 | [HttpPost] 29 | public async Task Crawling([FromBody] Protocols.Request.Crawling crawling) 30 | { 31 | return await _crawlingService.Execute(crawling); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Server/Controllers/NotificationController.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Models; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using Server.Services; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | 8 | namespace Server.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class NotificationController : ControllerBase 13 | { 14 | private readonly ILogger _logger; 15 | 16 | private readonly NotificationService _notificationService; 17 | 18 | public NotificationController(ILogger logger, NotificationService sourceService) 19 | { 20 | _logger = logger; 21 | _notificationService = sourceService; 22 | } 23 | 24 | 25 | [HttpGet] 26 | public async Task All() 27 | { 28 | return new Protocols.Response.NotificationMulti 29 | { 30 | Datas = MapperUtil.Map, 31 | List> 32 | (await _notificationService.All()) 33 | }; 34 | } 35 | 36 | [HttpPost] 37 | public async Task Create([FromBody] Protocols.Request.NotificationCreate notificaion) 38 | { 39 | return await _notificationService.Create(notificaion); 40 | } 41 | 42 | [HttpPut] 43 | public async Task Update([FromBody] Protocols.Request.NotificationUpdate notificaion) 44 | { 45 | return await _notificationService.Update(notificaion); 46 | } 47 | 48 | [HttpPost("Multi")] 49 | public async Task CreateMulti([FromBody] Protocols.Request.NotificationMulti notificaionMulti) 50 | { 51 | return await _notificationService.CreateMulti(notificaionMulti); 52 | } 53 | 54 | 55 | [HttpGet("{id}")] 56 | public async Task Get(string id) 57 | { 58 | return await _notificationService.Get(id); 59 | } 60 | 61 | [HttpPut("{id}")] 62 | public async Task Update(string id, [FromBody] Protocols.Request.NotificationUpdate notificaion) 63 | { 64 | return await _notificationService.Update(id, notificaion); 65 | } 66 | 67 | [HttpDelete("{id}")] 68 | public async Task Delete(string id) 69 | { 70 | return await _notificationService.Delete(id); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Server/Controllers/SourceController.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Models; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using Server.Services; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | 8 | namespace Server.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class SourceController : ControllerBase 13 | { 14 | private readonly ILogger _logger; 15 | 16 | private readonly SourceService _sourceService; 17 | 18 | public SourceController(ILogger logger, SourceService sourceService) 19 | { 20 | _logger = logger; 21 | _sourceService = sourceService; 22 | } 23 | 24 | 25 | 26 | [HttpGet] 27 | public async Task All() 28 | { 29 | return new Protocols.Response.SourceMulti 30 | { 31 | Datas = MapperUtil.Map, 32 | List> 33 | (await _sourceService.All()) 34 | }; 35 | } 36 | 37 | [HttpPost] 38 | public async Task Create([FromBody] Protocols.Request.Source source) 39 | { 40 | return await _sourceService.Create(source); 41 | } 42 | 43 | [HttpPost("Multi")] 44 | public async Task CreateMulti([FromBody] Protocols.Request.SourceMulti sourceMulti) 45 | { 46 | return await _sourceService.CreateMulti(sourceMulti); 47 | } 48 | 49 | 50 | [HttpGet("{id}")] 51 | public async Task Get(string id) 52 | { 53 | return await _sourceService.GetById(id); 54 | } 55 | 56 | [HttpPut("{id}")] 57 | public async Task Update(string id, [FromBody] Protocols.Request.Source source) 58 | { 59 | return await _sourceService.Update(id, source); 60 | } 61 | 62 | [HttpDelete("{id}")] 63 | public async Task Delete(string id) 64 | { 65 | return await _sourceService.Delete(id); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Server/Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base 4 | USER app 5 | WORKDIR /app 6 | EXPOSE 8080 7 | EXPOSE 8081 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build 10 | ARG BUILD_CONFIGURATION=Release 11 | WORKDIR /src 12 | COPY ["nuget.config", "."] 13 | COPY ["Server/Server.csproj", "Server/"] 14 | COPY ["WebCrawler/WebCrawler.csproj", "WebCrawler/"] 15 | RUN dotnet restore "./Server/Server.csproj" 16 | COPY . . 17 | WORKDIR "/src/Server" 18 | RUN dotnet build "./Server.csproj" -c $BUILD_CONFIGURATION -o /app/build 19 | 20 | FROM build AS publish 21 | ARG BUILD_CONFIGURATION=Release 22 | RUN dotnet publish "./Server.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false 23 | 24 | FROM base AS final 25 | WORKDIR /app 26 | COPY --from=publish /app/publish . 27 | ENTRYPOINT ["dotnet", "Server.dll"] -------------------------------------------------------------------------------- /Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Hosting; 3 | 4 | namespace Server 5 | { 6 | public static class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | CreateHostBuilder(args).Build().Run(); 11 | } 12 | 13 | private static IHostBuilder CreateHostBuilder(string[] args) => 14 | Host.CreateDefaultBuilder(args) 15 | .ConfigureWebHostDefaults(webBuilder => 16 | { 17 | webBuilder.UseStartup(); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Server/Protocols/Common/CrawlingData.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Converters; 3 | using System; 4 | using WebCrawler.Code; 5 | 6 | namespace Server.Protocols.Common 7 | { 8 | public class CrawlingData : Header 9 | { 10 | [JsonConverter(typeof(StringEnumConverter))] 11 | public CrawlingType Type { get; set; } 12 | 13 | public string BoardId { get; set; } 14 | 15 | public string BoardName { get; set; } 16 | 17 | public string Author { get; set; } 18 | 19 | public string SourceId { get; set; } 20 | 21 | public string Href { get; set; } 22 | 23 | public string Category { get; set; } 24 | 25 | public int Count { get; set; } 26 | 27 | public int Recommend { get; set; } 28 | 29 | public string Title { get; set; } 30 | 31 | public DateTime DateTime { get; set; } 32 | 33 | public long? RowId { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Server/Protocols/Common/Header.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Server.Protocols.Common 4 | { 5 | public class Header 6 | { 7 | public string Id { get; set; } 8 | 9 | public DateTime Created { get; set; } 10 | 11 | public DateTime? Updated { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Server/Protocols/Common/Notification.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Notification.Types; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Converters; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Server.Protocols.Common 8 | { 9 | public class Notification : Header 10 | { 11 | [JsonConverter(typeof(StringEnumConverter))] 12 | public NotificationType Type { get; set; } 13 | 14 | public string Name { get; set; } 15 | 16 | public string HookUrl { get; set; } 17 | 18 | public string Channel { get; set; } 19 | 20 | public string IconUrl { get; set; } 21 | 22 | public string SourceId { get; set; } 23 | 24 | public string Keyword { get; set; } 25 | 26 | public string Prefix { get; set; } 27 | 28 | public string Postfix { get; set; } 29 | 30 | public string FilterKeyword { get; set; } 31 | 32 | public string CrawlingType { get; set; } 33 | 34 | [JsonProperty(ItemConverterType = typeof(StringEnumConverter))] 35 | public List FilterDayOfWeeks { get; set; } = new(); 36 | 37 | public string FilterStartTime { get; set; } 38 | 39 | public string FilterEndTime { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Server/Protocols/Common/NotificationCreate.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Notification.Types; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Converters; 4 | using System; 5 | using System.Collections.Generic; 6 | using WebCrawler.Code; 7 | 8 | namespace Server.Protocols.Common 9 | { 10 | public class NotificationCreate 11 | { 12 | [JsonConverter(typeof(StringEnumConverter))] 13 | public NotificationType Type { get; set; } 14 | 15 | public string Name { get; set; } 16 | 17 | public string HookUrl { get; set; } 18 | 19 | public string Channel { get; set; } 20 | 21 | public string IconUrl { get; set; } 22 | 23 | [JsonConverter(typeof(StringEnumConverter))] 24 | public CrawlingType CrawlingType { get; set; } 25 | 26 | public string BoardName { get; set; } 27 | 28 | public string Keyword { get; set; } 29 | 30 | public string Prefix { get; set; } 31 | 32 | public string Postfix { get; set; } 33 | 34 | public string FilterKeyword { get; set; } 35 | 36 | [JsonProperty(ItemConverterType = typeof(StringEnumConverter))] 37 | public List FilterDayOfWeeks { get; set; } = new List(); 38 | 39 | public string FilterStartTime { get; set; } 40 | 41 | public string FilterEndTime { get; set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Server/Protocols/Common/Source.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Converters; 3 | using WebCrawler.Code; 4 | 5 | namespace Server.Protocols.Common 6 | { 7 | public class Source : Header 8 | { 9 | [JsonConverter(typeof(StringEnumConverter))] 10 | public CrawlingType Type { get; set; } 11 | 12 | public string BoardId { get; set; } 13 | 14 | public string Name { get; set; } 15 | 16 | public int PageMin { get; set; } = 1; 17 | 18 | public int PageMax { get; set; } = 1; 19 | 20 | public int Interval { get; set; } = 1000; 21 | 22 | public bool Switch { get; set; } = true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Server/Protocols/Request/Crawling.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Server.Protocols.Request 4 | { 5 | public class Crawling : EzAspDotNet.Protocols.RequestHeader 6 | { 7 | public List Sources { get; set; } 8 | 9 | public bool All { get; init; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/Protocols/Request/CrawlingList.cs: -------------------------------------------------------------------------------- 1 | using WebCrawler.Code; 2 | 3 | namespace Server.Protocols.Request 4 | { 5 | public class CrawlingList : EzAspDotNet.Protocols.Page.Pageable 6 | { 7 | public string Keyword { get; set; } 8 | 9 | public CrawlingType? Type { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/Protocols/Request/NotificationCreate.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Server.Protocols.Request 3 | { 4 | public class NotificationCreate : EzAspDotNet.Protocols.RequestHeader 5 | { 6 | public Common.NotificationCreate Data { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Server/Protocols/Request/NotificationMulti.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Server.Protocols.Request 4 | { 5 | public class NotificationMulti : EzAspDotNet.Protocols.RequestHeader 6 | { 7 | public List Datas { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Server/Protocols/Request/NotificationUpdate.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Server.Protocols.Request 3 | { 4 | public class NotificationUpdate : EzAspDotNet.Protocols.RequestHeader 5 | { 6 | public Common.Notification Data { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Server/Protocols/Request/Source.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | namespace Server.Protocols.Request 4 | { 5 | public class Source : EzAspDotNet.Protocols.RequestHeader 6 | { 7 | public Common.Source Data { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Server/Protocols/Request/SourceMulti.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Server.Protocols.Request 4 | { 5 | public class SourceMulti : EzAspDotNet.Protocols.RequestHeader 6 | { 7 | public List Datas { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Server/Protocols/Response/CodeList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Server.Protocols.Response 4 | { 5 | public class CodeList : EzAspDotNet.Protocols.ResponseHeader 6 | { 7 | public List Datas = new(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Server/Protocols/Response/Crawling.cs: -------------------------------------------------------------------------------- 1 | using Server.Protocols.Common; 2 | 3 | namespace Server.Protocols.Response 4 | { 5 | public class Crawling : EzAspDotNet.Protocols.ResponseHeader 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Server/Protocols/Response/CrawlingList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | 4 | namespace Server.Protocols.Response 5 | { 6 | public class CrawlingList : Pagable 7 | { 8 | public List Datas = new List(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Server/Protocols/Response/Notification.cs: -------------------------------------------------------------------------------- 1 | using Server.Protocols.Common; 2 | 3 | namespace Server.Protocols.Response 4 | { 5 | public class Notification : EzAspDotNet.Protocols.ResponseHeader 6 | { 7 | public Common.Notification Data { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Server/Protocols/Response/NotificationMulti.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Server.Protocols.Response 4 | { 5 | public class NotificationMulti : EzAspDotNet.Protocols.ResponseHeader 6 | { 7 | public List Datas { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Server/Protocols/Response/Pagable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Server.Protocols.Response 7 | { 8 | public class Pagable : EzAspDotNet.Protocols.ResponseHeader 9 | { 10 | public long Total { get; set; } 11 | 12 | public int Offset { get; set; } 13 | 14 | public int Limit { get; set; } 15 | 16 | public string Sort { get; set; } 17 | 18 | public bool Asc { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Server/Protocols/Response/Source.cs: -------------------------------------------------------------------------------- 1 | namespace Server.Protocols.Response 2 | { 3 | public class Source : EzAspDotNet.Protocols.ResponseHeader 4 | { 5 | public Common.Source Data { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Server/Protocols/Response/SourceMulti.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Server.Protocols.Response 7 | { 8 | public class SourceMulti : EzAspDotNet.Protocols.ResponseHeader 9 | { 10 | public List Datas { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Server/Server.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net9.0 5 | 7749a532-372b-44f3-a33f-0e77b2aee56a 6 | Linux 7 | .. 8 | 9 | 10 | 11 | true 12 | 13 | 14 | 15 | 16 | Always 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Http\%(RecursiveDir)%(Filename)%(Extension) 31 | false 32 | Never 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Server/Services/CrawlingLoopingService.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Exception; 2 | using EzAspDotNet.Services; 3 | using System; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace Server.Services 8 | { 9 | public class CrawlingLoopingService(CrawlingService crawlingService) : LoopingService 10 | { 11 | 12 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) 13 | { 14 | while (!stoppingToken.IsCancellationRequested) 15 | { 16 | try 17 | { 18 | await crawlingService.Execute(new Protocols.Request.Crawling { All = true }); 19 | } 20 | catch (Exception e) 21 | { 22 | e.ExceptionLog(); 23 | } 24 | 25 | await Task.Delay(TimeSpan.FromSeconds(30), stoppingToken); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Server/Services/CrawlingService.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Exception; 2 | using EzAspDotNet.Models; 3 | using EzAspDotNet.Notification.Models; 4 | using EzAspDotNet.Services; 5 | using EzAspDotNet.Util; 6 | using EzMongoDb.Util; 7 | using MongoDB.Driver; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | using WebCrawler; 13 | using WebCrawler.Code; 14 | using WebCrawler.Crawler; 15 | using WebCrawler.Models; 16 | 17 | namespace Server.Services 18 | { 19 | public class CrawlingService 20 | { 21 | private readonly MongoDbService _mongoDbService; 22 | 23 | private readonly SourceService _sourceService; 24 | 25 | private readonly WebHookService _webHookService; 26 | 27 | private readonly MongoDbUtil _mongoCrawlingData; 28 | 29 | public CrawlingService(MongoDbService mongoDbService, 30 | SourceService sourceService, 31 | WebHookService webHookService) 32 | { 33 | _mongoDbService = mongoDbService; 34 | _sourceService = sourceService; 35 | _webHookService = webHookService; 36 | _mongoCrawlingData = new MongoDbUtil(mongoDbService.Database); 37 | 38 | _mongoCrawlingData.Collection.Indexes.CreateMany(new List> 39 | { 40 | new(Builders.IndexKeys.Ascending(x => x.DateTime)), 41 | new(Builders.IndexKeys.Ascending(x => x.Title)), 42 | new(Builders.IndexKeys.Ascending(x => x.Type)), 43 | new(Builders.IndexKeys.Ascending(x => x.Type) 44 | .Ascending(x => x.BoardId)), 45 | new(Builders.IndexKeys.Ascending(x => x.Type) 46 | .Ascending(x => x.BoardId) 47 | .Ascending(x => x.Href), 48 | new CreateIndexOptions { Unique = true}) 49 | }); 50 | } 51 | 52 | public async Task Get(Protocols.Request.CrawlingList crawlingList) 53 | { 54 | var builder = Builders.Filter; 55 | var filter = FilterDefinition.Empty; 56 | if (!string.IsNullOrEmpty(crawlingList.Keyword)) 57 | { 58 | filter &= builder.Regex(x => x.Title, ".*" + crawlingList.Keyword + ".*"); 59 | } 60 | 61 | if (crawlingList.Type.HasValue) 62 | { 63 | filter &= builder.Eq(x => x.Type, crawlingList.Type.Value); 64 | } 65 | 66 | return new Protocols.Response.CrawlingList 67 | { 68 | ResultCode = EzAspDotNet.Protocols.Code.ResultCode.Success, 69 | Limit = crawlingList.Limit, 70 | Offset = crawlingList.Offset, 71 | Sort = crawlingList.Sort, 72 | Asc = crawlingList.Asc, 73 | Datas = MapperUtil.Map, List>(await _mongoCrawlingData.Page(filter, crawlingList.Limit, crawlingList.Offset, crawlingList.Sort, crawlingList.Asc)), 74 | Total = await _mongoCrawlingData.CountAsync(filter) 75 | }; 76 | } 77 | 78 | public async Task Execute(Protocols.Request.Crawling crawling) 79 | { 80 | var onCrawlDataDelegate = new CrawlDataDelegate(OnNewCrawlData); 81 | var sources = crawling.All ? 82 | MapperUtil.Map, List>(await _sourceService.All()) : 83 | crawling.Sources; 84 | 85 | var crawlerGroup = sources.Select(source => 86 | { 87 | var model = MapperUtil.Map(source); 88 | return source.Type switch 89 | { 90 | CrawlingType.DcInside => new DcInsideCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 91 | CrawlingType.Ruliweb => new RuliwebCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 92 | CrawlingType.Clien => new ClienCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 93 | CrawlingType.SlrClub => new SlrclubCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 94 | CrawlingType.Ppomppu => new PpomppuCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 95 | CrawlingType.TodayHumor => new TodayhumorCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 96 | CrawlingType.FmKorea => new FmkoreaCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 97 | CrawlingType.InvenNews => new InvenNewsCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 98 | CrawlingType.HumorUniv => new HumorUnivCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 99 | CrawlingType.Itcm => (CrawlerBase)new ItcmCrawler(onCrawlDataDelegate, _mongoDbService.Database, model), 100 | _ => throw new DeveloperException(EzAspDotNet.Protocols.Code.ResultCode.NotImplementedYet), 101 | }; 102 | }).GroupBy(x => x.GetType()); 103 | 104 | foreach(var group in crawlerGroup) 105 | { 106 | foreach(var crawler in group) 107 | { 108 | _ = crawler.RunAsync(); 109 | } 110 | } 111 | 112 | return new Protocols.Response.Crawling 113 | { 114 | ResultCode = EzAspDotNet.Protocols.Code.ResultCode.Success 115 | }; 116 | } 117 | 118 | private async Task OnNewCrawlData(CrawlingData crawlingData) 119 | { 120 | var category = string.IsNullOrEmpty(crawlingData.Category) ? string.Empty : $"[{crawlingData.Category}] "; 121 | await _webHookService.Execute(Builders.Filter.Eq(x => x.SourceId, crawlingData.SourceId), 122 | new EzAspDotNet.Notification.Data.WebHook 123 | { 124 | Title = $"{category}{crawlingData.Title}", 125 | Footer = crawlingData.Author, 126 | TitleLink = crawlingData.Href, 127 | TimeStamp = crawlingData.DateTime.ToTimeStamp() 128 | }); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Server/Services/NotificationService.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Exception; 2 | using EzAspDotNet.Models; 3 | using EzAspDotNet.Notification.Models; 4 | using EzAspDotNet.Notification.Types; 5 | using EzAspDotNet.Services; 6 | using EzMongoDb.Util; 7 | using MongoDB.Driver; 8 | using Server.Code; 9 | using System.Collections.Generic; 10 | using System.Threading.Tasks; 11 | using WebCrawler.Code; 12 | 13 | namespace Server.Services 14 | { 15 | public class NotificationService 16 | { 17 | private readonly MongoDbUtil _mongoDbNotification; 18 | 19 | private readonly SourceService _sourceService; 20 | 21 | public NotificationService(MongoDbService mongoDbService, 22 | SourceService sourceService) 23 | { 24 | _mongoDbNotification = new MongoDbUtil(mongoDbService.Database); 25 | _sourceService = sourceService; 26 | _mongoDbNotification.Collection.Indexes.CreateOne(new CreateIndexModel( 27 | Builders.IndexKeys.Ascending(x => x.SourceId) 28 | .Ascending(x => x.CrawlingType) 29 | .Ascending(x => x.Type))); 30 | } 31 | 32 | public async Task> All() 33 | { 34 | return await _mongoDbNotification.All(); 35 | } 36 | 37 | public async Task Create(Protocols.Request.NotificationCreate notification) 38 | { 39 | var created = await Create(notification.Data); 40 | if (created == null) 41 | { 42 | throw new DeveloperException(ResultCode.CreateFailedNotification); 43 | } 44 | 45 | return new Protocols.Response.Notification 46 | { 47 | Data = MapperUtil.Map(created) 48 | }; 49 | 50 | } 51 | 52 | private async Task GetSourceId(CrawlingType crawlingType, string boardName) 53 | { 54 | var source = await _sourceService.GetByName(crawlingType, boardName); 55 | if (source == null) 56 | { 57 | throw new DeveloperException(ResultCode.NotFoundSource); 58 | } 59 | 60 | return source.Id; 61 | } 62 | 63 | private static FilterDefinition GetFilterDefinition(string sourceId, string crawlingType, NotificationType notificationType) 64 | { 65 | return Builders.Filter.Eq(x => x.SourceId, sourceId) & 66 | Builders.Filter.Eq(x => x.CrawlingType, crawlingType) & 67 | Builders.Filter.Eq(x => x.Type, notificationType); 68 | } 69 | 70 | private async Task Create(Protocols.Common.NotificationCreate notification) 71 | { 72 | try 73 | { 74 | var sourceId = await GetSourceId(notification.CrawlingType, notification.BoardName); 75 | var notificationModel = MapperUtil.Map(notification); 76 | notificationModel.SourceId = sourceId; 77 | 78 | return await _mongoDbNotification.CreateAsync(notificationModel); 79 | } 80 | catch (MongoWriteException) 81 | { 82 | throw new DeveloperException(ResultCode.UsingNotificationId); 83 | } 84 | } 85 | 86 | public async Task CreateMulti(Protocols.Request.NotificationMulti notificationMulti) 87 | { 88 | var notifications = new List(); 89 | foreach (var notification in notificationMulti.Datas) 90 | { 91 | notifications.Add(await Create(notification)); 92 | } 93 | 94 | return new Protocols.Response.NotificationMulti 95 | { 96 | Datas = MapperUtil.Map, List>(notifications) 97 | }; 98 | } 99 | 100 | public async Task Get(string id) 101 | { 102 | var notification = await _mongoDbNotification.FindOneAsyncById(id); 103 | if (notification == null) 104 | { 105 | throw new DeveloperException(Code.ResultCode.NotFoundData); 106 | } 107 | 108 | return new Protocols.Response.Notification 109 | { 110 | Data = MapperUtil.Map(notification) 111 | }; 112 | } 113 | 114 | public async Task> Get(FilterDefinition filter) 115 | { 116 | return await _mongoDbNotification.FindAsync(filter); 117 | } 118 | 119 | public async Task Update(Protocols.Request.NotificationUpdate notificationUpdate) 120 | { 121 | var update = MapperUtil.Map(notificationUpdate.Data); 122 | if (update == null) 123 | { 124 | throw new DeveloperException(ResultCode.InvalidRequest); 125 | } 126 | 127 | var filter = GetFilterDefinition(update.SourceId, update.CrawlingType, update.Type); 128 | var updated = await _mongoDbNotification.UpsertAsync(filter, update); 129 | return new Protocols.Response.Notification 130 | { 131 | Data = MapperUtil.Map(updated) 132 | }; 133 | } 134 | 135 | public async Task Update(string id, Protocols.Request.NotificationUpdate notificationUpdate) 136 | { 137 | var update = MapperUtil.Map(notificationUpdate.Data); 138 | if (update == null) 139 | { 140 | throw new DeveloperException(ResultCode.InvalidRequest); 141 | } 142 | 143 | var updated = await _mongoDbNotification.UpdateAsync(id, update); 144 | return new Protocols.Response.Notification 145 | { 146 | Data = MapperUtil.Map(updated) 147 | }; 148 | } 149 | 150 | public async Task Delete(string id) 151 | { 152 | var deleted = await _mongoDbNotification.RemoveGetAsync(id); 153 | if (deleted == null) 154 | { 155 | throw new DeveloperException(ResultCode.NotFoundData); 156 | } 157 | 158 | return new Protocols.Response.Notification 159 | { 160 | Data = MapperUtil.Map(deleted) 161 | }; 162 | } 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /Server/Services/SourceService.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Exception; 2 | using EzAspDotNet.Models; 3 | using EzAspDotNet.Services; 4 | using EzMongoDb.Util; 5 | using MongoDB.Driver; 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | using WebCrawler.Code; 9 | using WebCrawler.Models; 10 | 11 | namespace Server.Services 12 | { 13 | public class SourceService 14 | { 15 | private readonly MongoDbUtil _mongoDbSource; 16 | 17 | public SourceService(MongoDbService mongoDbService) 18 | { 19 | _mongoDbSource = new MongoDbUtil(mongoDbService.Database); 20 | 21 | _mongoDbSource.Collection.Indexes.CreateOne(new CreateIndexModel( 22 | Builders.IndexKeys.Ascending(x => x.Type))); 23 | 24 | _mongoDbSource.Collection.Indexes.CreateOne(new CreateIndexModel( 25 | Builders.IndexKeys.Ascending(x => x.Type).Ascending(x => x.BoardId))); 26 | } 27 | 28 | public async Task> All() 29 | { 30 | return await _mongoDbSource.FindAsync(Builders.Filter.Eq(x => x.Switch, true)); 31 | } 32 | 33 | public async Task Create(Protocols.Request.Source source) 34 | { 35 | var created = await Create(source.Data); 36 | if (created == null) 37 | { 38 | throw new DeveloperException(Code.ResultCode.CreateFailedSource); 39 | } 40 | 41 | return new Protocols.Response.Source 42 | { 43 | ResultCode = EzAspDotNet.Protocols.Code.ResultCode.Success, 44 | Data = MapperUtil.Map(created), 45 | }; 46 | 47 | } 48 | 49 | private async Task Create(Protocols.Common.Source source) 50 | { 51 | try 52 | { 53 | return await _mongoDbSource.UpsertAsync(Builders.Filter.Eq(x => x.Type, source.Type) & 54 | Builders.Filter.Eq(x => x.BoardId, source.BoardId), 55 | MapperUtil.Map(source)); 56 | } 57 | catch (MongoWriteException) 58 | { 59 | throw new DeveloperException(Code.ResultCode.UsingSourceId); 60 | } 61 | } 62 | 63 | public async Task CreateMulti(Protocols.Request.SourceMulti sourceMulti) 64 | { 65 | var sources = new List(); 66 | foreach (var source in sourceMulti.Datas) 67 | { 68 | sources.Add(await Create(source)); 69 | } 70 | 71 | return new Protocols.Response.SourceMulti 72 | { 73 | Datas = MapperUtil.Map, 74 | List> 75 | (sources) 76 | }; 77 | } 78 | 79 | public async Task GetById(string id) 80 | { 81 | var source = await _mongoDbSource.FindOneAsyncById(id); 82 | if (source == null) 83 | { 84 | throw new DeveloperException(Code.ResultCode.CreateFailedSource); 85 | } 86 | 87 | return new Protocols.Response.Source 88 | { 89 | Data = MapperUtil.Map(source) 90 | }; 91 | } 92 | 93 | public async Task Get(CrawlingType crawlingType, string boardId) 94 | { 95 | return await _mongoDbSource.FindOneAsync(Builders.Filter.Eq(x => x.Type, crawlingType) & 96 | Builders.Filter.Eq(x => x.BoardId, boardId)); 97 | } 98 | 99 | public async Task GetByName(CrawlingType crawlingType, string boardName) 100 | { 101 | return await _mongoDbSource.FindOneAsync(Builders.Filter.Eq(x => x.Type, crawlingType) & 102 | Builders.Filter.Eq(x => x.Name, boardName)); 103 | } 104 | 105 | public async Task Update(string id, Protocols.Request.Source source) 106 | { 107 | var update = MapperUtil.Map(source.Data); 108 | update.Created = source.Data.Created; 109 | 110 | var updated = await _mongoDbSource.UpdateAsync(id, update); 111 | if (updated == null) 112 | { 113 | throw new DeveloperException(Code.ResultCode.NotFoundSource); 114 | } 115 | 116 | return new Protocols.Response.Source 117 | { 118 | Data = MapperUtil.Map(updated) 119 | }; 120 | } 121 | 122 | public async Task Delete(string id) 123 | { 124 | var deleted = await _mongoDbSource.RemoveGetAsync(id); 125 | if (deleted == null) 126 | { 127 | throw new DeveloperException(Code.ResultCode.NotFoundSource); 128 | } 129 | 130 | return new Protocols.Response.Source 131 | { 132 | Data = MapperUtil.Map(deleted) 133 | }; 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Server/Startup.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using EzAspDotNet.Exception; 3 | using EzAspDotNet.Services; 4 | using EzAspDotNet.StartUp; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.OpenApi.Models; 11 | using Serilog; 12 | using Server.Services; 13 | using System; 14 | using System.Text; 15 | 16 | namespace Server 17 | { 18 | 19 | public class Startup 20 | { 21 | public Startup(IConfiguration configuration) 22 | { 23 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 24 | 25 | var serilogConfig = new ConfigurationBuilder() 26 | .AddJsonFile("serilog.json") 27 | .Build(); 28 | 29 | Log.Logger = new LoggerConfiguration() 30 | .ReadFrom.Configuration(serilogConfig) 31 | .CreateLogger(); 32 | 33 | Configuration = configuration; 34 | } 35 | 36 | public IConfiguration Configuration { get; } 37 | 38 | // This method gets called by the runtime. Use this method to add services to the container. 39 | public void ConfigureServices(IServiceCollection services) 40 | { 41 | EzAspDotNet.Models.MapperUtil.Initialize( 42 | new MapperConfiguration(cfg => 43 | { 44 | cfg.AllowNullDestinationValues = true; 45 | 46 | cfg.CreateMap(MemberList.None); 47 | cfg.CreateMap(MemberList.None); 48 | 49 | cfg.CreateMap(MemberList.None) 50 | .ForMember(d => d.Created, o => o.MapFrom(s => DateTime.Now)); 51 | 52 | cfg.CreateMap(MemberList.None); 53 | cfg.CreateMap(MemberList.None) 54 | .ForMember(d => d.Created, o => o.MapFrom(s => DateTime.Now)); 55 | 56 | cfg.CreateMap(MemberList.None); 57 | cfg.CreateMap(MemberList.None); 58 | }) 59 | ); 60 | 61 | services.CommonConfigureServices(); 62 | 63 | services.AddHttpClient(); 64 | 65 | services.AddControllers().AddNewtonsoftJson(); 66 | 67 | services.AddCors(options => options.AddPolicy("AllowSpecificOrigin", 68 | builder => 69 | { 70 | builder.AllowAnyOrigin() 71 | .AllowAnyHeader() 72 | .AllowAnyMethod(); 73 | })); 74 | 75 | services.AddSwaggerGen(c => 76 | { 77 | c.SwaggerDoc("v2", new OpenApiInfo { Title = "API", Version = "v2" }); 78 | }); 79 | 80 | services.ConfigureSwaggerGen(options => 81 | { 82 | options.CustomSchemaIds(x => x.FullName); 83 | }); 84 | 85 | services.AddSingleton(); 86 | services.AddSingleton(); 87 | services.AddSingleton(); 88 | services.AddSingleton(); 89 | services.AddSingleton(); 90 | services.AddSingleton(); 91 | 92 | Log.Logger.Warning("Local TimeZone:{Local}", TimeZoneInfo.Local); 93 | } 94 | 95 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 96 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 97 | { 98 | if (env.IsDevelopment()) 99 | { 100 | app.UseDeveloperExceptionPage(); 101 | } 102 | else 103 | { 104 | //app.UseHttpsRedirection(); 105 | } 106 | 107 | app.UseCors("AllowSpecificOrigin"); 108 | 109 | app.ConfigureExceptionHandler(); 110 | 111 | app.UseRouting(); 112 | 113 | app.UseAuthorization(); 114 | 115 | app.UseEndpoints(endpoints => 116 | { 117 | endpoints.MapControllers(); 118 | }); 119 | 120 | app.UseSwagger(c => 121 | { 122 | c.SerializeAsV2 = true; 123 | }); 124 | 125 | app.UseSwaggerUI(c => 126 | { 127 | c.SwaggerEndpoint("v1/swagger.json", "My API V1"); 128 | }); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Server/appsettings.Production.json.sample: -------------------------------------------------------------------------------- 1 | { 2 | "MongoDb": { 3 | "ConnectionString": "mongodb://{아이디}:{비밀번호}@{호스트}:{포트}/?maxPoolSize={풀 사이즈}&waitQueueSize={큐 사이즈, 풀 사이즈x4 권장}", 4 | "DatabaseName": "web-crawler" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MongoDb": { 3 | "ConnectionString": "mongodb://localhost:27017/?maxPoolSize=500&waitQueueSize=2000", 4 | "DatabaseName": "web-crawler" 5 | }, 6 | "Logging": { 7 | "LogLevel": { 8 | "Default": "Warning", 9 | "Microsoft": "Warning", 10 | "Microsoft.Hosting.Lifetime": "Warning" 11 | } 12 | }, 13 | "AllowedHosts": "*" 14 | } 15 | -------------------------------------------------------------------------------- /Server/serilog.json: -------------------------------------------------------------------------------- 1 | { 2 | "Serilog": { 3 | "Using": [ "Serilog.Sinks.Console" ], 4 | "MinimumLevel": "Warning", 5 | "WriteTo": [ 6 | { "Name": "Console" }, 7 | { 8 | "Name": "File", 9 | "Args": { 10 | "path": "Logs\\web-crawler-.log", 11 | "rollingInterval": "Day" 12 | } 13 | } 14 | ], 15 | "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], 16 | "Destructure": [ 17 | { 18 | "Name": "ToMaximumDepth", 19 | "Args": { "maximumDestructuringDepth": 4 } 20 | }, 21 | { 22 | "Name": "ToMaximumStringLength", 23 | "Args": { "maximumStringLength": 100 } 24 | }, 25 | { 26 | "Name": "ToMaximumCollectionCount", 27 | "Args": { "maximumCollectionCount": 10 } 28 | } 29 | ], 30 | "Properties": { 31 | "Application": "web-crawler" 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Server/serilog.json.sample: -------------------------------------------------------------------------------- 1 | { 2 | "Serilog": { 3 | "Using": [ "Serilog.Sinks.Console" ], 4 | "MinimumLevel": "Information", 5 | "WriteTo": [ 6 | { "Name": "Console" }, 7 | { 8 | "Name": "File", 9 | "Args": { 10 | "path": "Logs\\web-crawler-.log", 11 | "rollingInterval": "Day" 12 | } 13 | } 14 | ], 15 | "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], 16 | "Destructure": [ 17 | { 18 | "Name": "ToMaximumDepth", 19 | "Args": { "maximumDestructuringDepth": 4 } 20 | }, 21 | { 22 | "Name": "ToMaximumStringLength", 23 | "Args": { "maximumStringLength": 100 } 24 | }, 25 | { 26 | "Name": "ToMaximumCollectionCount", 27 | "Args": { "maximumCollectionCount": 10 } 28 | } 29 | ], 30 | "Properties": { 31 | "Application": "web-crawler" 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /UnitTest/UnitTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net9.0 5 | enable 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /UnitTest/WebCrawler.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elky84/web-crawler/13d7a6514751dace84eaef6ae851c9581befb136/UnitTest/WebCrawler.cs -------------------------------------------------------------------------------- /WebCrawler/Code/CrawlingType.cs: -------------------------------------------------------------------------------- 1 | namespace WebCrawler.Code 2 | { 3 | public enum CrawlingType 4 | { 5 | Clien, 6 | Ruliweb, 7 | FmKorea, 8 | SlrClub, 9 | Ppomppu, 10 | TodayHumor, 11 | InvenNews, 12 | HumorUniv, 13 | Itcm, 14 | DcInside, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/ClienCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using AngleSharp.Dom; 8 | using WebCrawler.Models; 9 | 10 | namespace WebCrawler.Crawler 11 | { 12 | public class ClienCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 13 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"https://www.clien.net/service/board/{source.BoardId}", source) 14 | { 15 | protected override string UrlComposite(int page) 16 | { 17 | // 페이지가 0부터 시작함 18 | return $"{UrlBase}?od=T32&po={page - 1}"; 19 | } 20 | 21 | protected override void OnPageCrawl(IDocument document) 22 | { 23 | var tdContent = document.QuerySelectorAll("div") 24 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.Contains("list_item") && x.ClassName.Contains("symph_row")) 25 | .Select(x => 26 | { 27 | var stringTuples = x.QuerySelectorAll("span") 28 | .Select(y => 29 | { 30 | var text = y.TextContent.Trim(); 31 | if (string.IsNullOrEmpty(text)) 32 | { 33 | text = y.QuerySelector("img")?.GetAttribute("alt"); 34 | } 35 | 36 | return new Tuple(y.ClassName, text); 37 | }).ToList(); 38 | 39 | var a = x.QuerySelectorAll("a"); 40 | 41 | stringTuples.AddRange(a.Where(x => !string.IsNullOrEmpty(x.ClassName)) 42 | .Select(y => new Tuple(y.ClassName, y.TextContent)) 43 | .ToList()); 44 | 45 | var hrefs = a.Select(x => x.GetAttribute("href")) 46 | .ToList(); 47 | 48 | return new Tuple>, List>(stringTuples, hrefs); 49 | }) 50 | .ToArray(); 51 | 52 | foreach(var (stringTuples, hrefs) in tdContent) 53 | { 54 | var category = stringTuples.FindValue("category_fixed"); 55 | if (string.IsNullOrEmpty(category)) 56 | { 57 | category = stringTuples.FindValue("icon_keyword"); 58 | }; 59 | 60 | var title = stringTuples.FindValue("subject_fixed"); 61 | if (string.IsNullOrEmpty(title)) 62 | { 63 | title = stringTuples.FindValue("list_subject"); 64 | }; 65 | 66 | title = title.Substring("\n"); 67 | 68 | var author = stringTuples.FindValue("nickname"); 69 | var count = stringTuples.FindValue("hit").ToIntShorthand(); 70 | var date = DateTime.Parse(stringTuples.FindValue("timestamp")); 71 | 72 | var href = UrlCompositeHref(hrefs[0]); 73 | 74 | _ = OnCrawlData(new CrawlingData 75 | { 76 | Type = Source.Type, 77 | BoardId = Source.BoardId, 78 | BoardName = Source.Name, 79 | Category = category, 80 | Title = title, 81 | Author = author, 82 | Count = count, 83 | DateTime = date, 84 | Href = href, 85 | SourceId = Source.Id 86 | }); 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/CrawlerBase.cs: -------------------------------------------------------------------------------- 1 | using AngleSharp.Html.Parser; 2 | using EzAspDotNet.Util; 3 | using EzMongoDb.Util; 4 | using MongoDB.Driver; 5 | using Serilog; 6 | using System; 7 | using System.Collections.Concurrent; 8 | using System.Linq; 9 | using System.Net; 10 | using System.Net.Http; 11 | using System.Net.Http.Headers; 12 | using System.Runtime.InteropServices; 13 | using System.Text; 14 | using System.Threading; 15 | using System.Threading.Tasks; 16 | using AngleSharp; 17 | using AngleSharp.Dom; 18 | using WebCrawler.Models; 19 | 20 | namespace WebCrawler.Crawler 21 | { 22 | public delegate Task CrawlDataDelegate(CrawlingData data); 23 | 24 | public abstract class CrawlerBase 25 | { 26 | protected string UrlBase { get; set; } 27 | 28 | protected Source Source { get; set; } 29 | 30 | protected string Host { get; set; } 31 | 32 | private readonly MongoDbUtil _mongoDbCrawlingData; 33 | 34 | private CrawlDataDelegate OnCrawlDataDelegate { get; set; } 35 | 36 | private int _executing; 37 | 38 | protected CrawlerBase(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, string urlBase, Source source) 39 | { 40 | if (mongoDb != null) 41 | { 42 | _mongoDbCrawlingData = new MongoDbUtil(mongoDb); 43 | } 44 | 45 | OnCrawlDataDelegate = onCrawlDataDelegate; 46 | UrlBase = urlBase; 47 | 48 | var uri = new Uri(urlBase); 49 | Host = $"{uri.Scheme}://{uri.Host}"; 50 | 51 | Source = source; 52 | } 53 | 54 | private static HttpClient CreateHttpClient() 55 | { 56 | var handler = new HttpClientHandler { UseCookies = true}; 57 | 58 | var client = new HttpClient(handler); 59 | client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0"); 60 | client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true }; 61 | return client; 62 | } 63 | 64 | public virtual async Task RunAsync() 65 | { 66 | for (var page = Source.PageMin; page <= Source.PageMax; ++page) 67 | { 68 | try 69 | { 70 | await ExecuteAsync(page); 71 | } 72 | catch (Exception ex) 73 | { 74 | Log.Error(ex, "Error while running page {page}", page); 75 | } 76 | Thread.Sleep(Source.Interval); 77 | } 78 | } 79 | 80 | protected virtual bool CanTwice() => true; 81 | 82 | protected async Task ExecuteAsync(int page) 83 | { 84 | if (!CanTwice() && 0 != Interlocked.Exchange(ref _executing, 1)) return false; 85 | var builder = new UriBuilder(UrlComposite(page)); 86 | await Crawling(builder.Uri); 87 | Interlocked.Exchange(ref _executing, 0); 88 | return true; 89 | } 90 | 91 | protected abstract string UrlComposite(int page); 92 | 93 | private async Task Crawling(Uri uri) 94 | { 95 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 96 | 97 | using var client = CreateHttpClient(); 98 | var response = await client.GetAsync(uri.AbsoluteUri); 99 | if (response.StatusCode != HttpStatusCode.OK) 100 | { 101 | Log.Logger.Error("response failed. ", uri.AbsoluteUri, response.StatusCode); 102 | return; 103 | } 104 | 105 | var responseBytes = await response.Content.ReadAsByteArrayAsync(); 106 | 107 | var charset = response.Content.Headers.ContentType?.CharSet; 108 | Encoding encoding; 109 | 110 | if (!string.IsNullOrEmpty(charset)) 111 | { 112 | try 113 | { 114 | encoding = Encoding.GetEncoding(charset); 115 | } 116 | catch 117 | { 118 | encoding = Encoding.UTF8; 119 | } 120 | } 121 | else 122 | { 123 | encoding = Encoding.GetEncoding("EUC-KR"); 124 | } 125 | 126 | var decodedString = encoding.GetString(responseBytes); 127 | 128 | if (string.IsNullOrEmpty(decodedString)) 129 | { 130 | Log.Logger.Error("Response content is null."); 131 | return; 132 | } 133 | 134 | var config = Configuration.Default; 135 | var context = BrowsingContext.New(config); 136 | 137 | var parser = new HtmlParser(new HtmlParserOptions { IsEmbedded = true }, context); 138 | var document = await parser.ParseDocumentAsync(decodedString); 139 | OnPageCrawl(document); 140 | } 141 | 142 | protected abstract void OnPageCrawl(AngleSharp.Dom.IDocument document); 143 | 144 | protected virtual string UrlCompositeHref(string href) 145 | { 146 | return UrlBase.CutAndComposite("/", 0, 3, href); 147 | } 148 | 149 | protected async Task OnCrawlData(CrawlingData crawlingData) 150 | { 151 | // 글자 뒤의 공백 날리기 152 | crawlingData.Title = crawlingData.Title.TrimEnd(); 153 | 154 | // 현재시간보다 크다면, 시간만 담긴 데이터에서 전날 글에 대한 시간 + 오늘 날짜로 값이 들어와서 그런 것. 이에 대한 예외처리 155 | if (crawlingData.DateTime > DateTime.Now) 156 | { 157 | crawlingData.DateTime = crawlingData.DateTime.AddDays(-1); 158 | } 159 | 160 | var builder = Builders.Filter; 161 | var filter = builder.Eq(x => x.Type, crawlingData.Type) & 162 | builder.Eq(x => x.BoardId, crawlingData.BoardId) & 163 | builder.Eq(x => x.Href, crawlingData.Href); 164 | 165 | if (_mongoDbCrawlingData != null) 166 | { 167 | await _mongoDbCrawlingData.UpsertAsync(filter, crawlingData, 168 | CreateAction); 169 | } 170 | 171 | return crawlingData; 172 | } 173 | 174 | private async void CreateAction(CrawlingData crawlingData) 175 | { 176 | if (OnCrawlDataDelegate != null) 177 | { 178 | await OnCrawlDataDelegate.Invoke(crawlingData); 179 | } 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/DcInsideCrawler.cs: -------------------------------------------------------------------------------- 1 | using AngleSharp.Dom; 2 | using EzAspDotNet.Util; 3 | using MongoDB.Driver; 4 | using Serilog; 5 | using System; 6 | using System.Globalization; 7 | using System.Linq; 8 | using System.Text.RegularExpressions; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using WebCrawler.Models; 12 | 13 | namespace WebCrawler.Crawler 14 | { 15 | public partial class DcInsideCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 16 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"https://gall.dcinside.com/{source.BoardId}", source) 17 | { 18 | protected override string UrlComposite(int page) 19 | { 20 | return $"{UrlBase}&page={page}"; 21 | } 22 | 23 | protected override void OnPageCrawl(IDocument document) 24 | { 25 | var cultureInfo = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); 26 | var calendar = cultureInfo.Calendar; 27 | calendar.TwoDigitYearMax = DateTime.Now.Year + 30; 28 | cultureInfo.DateTimeFormat.Calendar = calendar; 29 | 30 | var thContent = document.QuerySelectorAll("thead tr th") 31 | .Select(x => x.TextContent.Trim()) 32 | .ToList(); 33 | 34 | var tdContent = document.QuerySelectorAll("table tbody tr") 35 | .Where(x => x.ClassName?.Contains("us-post") ?? false) 36 | .SelectMany(x => x.QuerySelectorAll("td") 37 | .Select(cell => 38 | { 39 | var cleanHtml = Regex.Replace(cell.InnerHtml, "<[^>]*?>.*?

", "", RegexOptions.IgnoreCase); 40 | var textContent = Regex.Replace(cleanHtml, @"<[^>]+>", "").Trim(); 41 | return string.IsNullOrWhiteSpace(textContent) ? "" : textContent; 42 | })) 43 | .ToArray(); 44 | 45 | var tdHref = document.QuerySelectorAll("tbody tr") 46 | .Select(x => x.QuerySelectorAll("td")) 47 | .SelectMany(x => x.Where(y => y.QuerySelector("a") != null) 48 | .Select(y => y.QuerySelector("a").GetAttribute("href"))) 49 | .Where(x => !string.IsNullOrEmpty(x) && x.Contains("board/view")) 50 | .ToArray(); 51 | 52 | if (!thContent.Any() || !tdContent.Any()) 53 | { 54 | Log.Error("Parsing Failed DOM. Not has thContent or tdContent {UrlComposite}", UrlComposite(1)); 55 | return; 56 | } 57 | 58 | for(var n = 0; n < tdContent.Length / thContent.Count; ++n) 59 | { 60 | var cursor = n * thContent.Count; 61 | var id = tdContent.GetValue(thContent, "번호", cursor).ToIntRegex(); 62 | var category = tdContent.GetValue(thContent, "말머리", cursor); 63 | var title = tdContent.GetValue(thContent, "제목", cursor).Substring("\n"); 64 | var author = tdContent.GetValue(thContent, "글쓴이", cursor); 65 | var recommend = tdContent.GetValue(thContent, "추천", cursor).ToIntNullable(); 66 | var count = tdContent.GetValue(thContent, "조회", cursor).ToInt(); 67 | 68 | var dateTimeStr = tdContent.GetValue(thContent, "작성일", cursor); 69 | var date = ParseDate(dateTimeStr); 70 | 71 | var href = tdHref[n]; 72 | 73 | _ = OnCrawlData(new CrawlingData 74 | { 75 | Type = Source.Type, 76 | BoardId = Source.BoardId, 77 | BoardName = Source.Name, 78 | Category = category, 79 | Title = title, 80 | Author = author, 81 | Recommend = recommend.GetValueOrDefault(0), 82 | Count = count, 83 | DateTime = date.GetValueOrDefault(DateTime.Now), 84 | RowId = id, 85 | Href = Host + href, 86 | SourceId = Source.Id 87 | }); 88 | } 89 | } 90 | 91 | static DateTime? ParseDate(string dateTimeStr) 92 | { 93 | CultureInfo cultureInfo = CultureInfo.InvariantCulture; 94 | int currentYear = DateTime.Now.Year; 95 | DateTime today = DateTime.Today; 96 | 97 | if (dateTimeStr.Contains('.')) 98 | { 99 | return dateTimeStr.Split('.').Length >= 3 100 | ? DateTime.ParseExact(dateTimeStr, "yy.MM.dd", cultureInfo) 101 | : new DateTime(currentYear, int.Parse(dateTimeStr.Split('.')[0]), int.Parse(dateTimeStr.Split('.')[1])); 102 | } 103 | else if (dateTimeStr.Contains(':')) 104 | { 105 | TimeSpan time = TimeSpan.Parse(dateTimeStr); 106 | return today.Add(time); 107 | } 108 | else 109 | { 110 | return DateTime.Parse(dateTimeStr); 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/FmkoreaCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using Serilog; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using AngleSharp.Dom; 9 | using WebCrawler.Models; 10 | 11 | namespace WebCrawler.Crawler 12 | { 13 | public class FmkoreaCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 14 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"https://www.fmkorea.com/index.php", source) 15 | { 16 | protected override string UrlComposite(int page) 17 | { 18 | return $"{UrlBase}?mid={Source.BoardId}&page={page}"; 19 | } 20 | 21 | protected override void OnPageCrawl(IDocument document) 22 | { 23 | var thContent = document.QuerySelectorAll("thead tr th").Select(x => x.TextContent.Trim()).ToArray(); 24 | if (thContent.Any()) 25 | { 26 | OnPageCrawlTable(document, thContent); 27 | } 28 | else 29 | { 30 | OnPageCrawlList(document); 31 | } 32 | } 33 | 34 | protected override bool CanTwice() => false; 35 | 36 | private void OnPageCrawlTable(IDocument document, string[] thContent) 37 | { 38 | var tdAll = document.QuerySelectorAll("tbody tr td") 39 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && !x.ClassName.Contains("notice")); 40 | 41 | var tdContent = tdAll.Select(x => x.TextContent.Trim()).ToArray(); 42 | 43 | var tdHref = tdAll.Where(x => x.ClassName.Contains("title")) 44 | .Select(x => x.QuerySelector("a").GetAttribute("href")).ToArray(); 45 | 46 | if (!thContent.Any() || !tdContent.Any()) 47 | { 48 | Log.Error($"Parsing Failed DOM. Not has thContent or tdContent {UrlComposite(1)}"); 49 | return; 50 | } 51 | 52 | for(var n = 0; n < tdContent.Length / thContent.Length; ++n) 53 | { 54 | var cursor = n * thContent.Length; 55 | var category = tdContent[cursor + 0]; 56 | var title = tdContent[cursor + 1]; 57 | var author = tdContent[cursor + 2]; 58 | var date = DateTime.Parse(tdContent[cursor + 3]); 59 | var count = tdContent[cursor + 4].ToInt(); 60 | var recommend = tdContent[cursor + 5].ToInt(); 61 | 62 | var href = UrlCompositeHref(tdHref[n]); 63 | 64 | _ = OnCrawlData(new CrawlingData 65 | { 66 | Type = Source.Type, 67 | BoardId = Source.BoardId, 68 | BoardName = Source.Name, 69 | Category = category, 70 | Title = title.Substring("\t"), 71 | Author = author, 72 | Recommend = recommend, 73 | Count = count, 74 | DateTime = date, 75 | Href = href, 76 | SourceId = Source.Id 77 | }); 78 | } 79 | } 80 | 81 | private void OnPageCrawlList(IDocument document) 82 | { 83 | var tdContent = document.QuerySelectorAll("ul li div") 84 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.Contains("li")) 85 | .Select(x => 86 | { 87 | var tuples = x.QuerySelectorAll("h3") 88 | .Select(y => 89 | { 90 | var textContent = y.TextContent.Trim(); 91 | 92 | var lastBracket = textContent.LastIndexOf("["); 93 | if (lastBracket != -1) 94 | { 95 | textContent = textContent.Substring(0, lastBracket); 96 | } 97 | 98 | return new Tuple("title", textContent); 99 | }).ToList(); 100 | 101 | tuples.AddRange(x.QuerySelectorAll("span") 102 | .Select(y => new Tuple(y.ClassName, y.TextContent.Trim())) 103 | .ToList()); 104 | 105 | tuples.AddRange(x.QuerySelectorAll("div") 106 | .Where(y => !string.IsNullOrEmpty(y.ClassName) && y.ClassName == "hotdeal_info") 107 | .Select(y => new Tuple("info", y.TextContent.Replace("\t", string.Empty))) 108 | .ToList()); 109 | 110 | var hrefs = x.QuerySelectorAll("a") 111 | .Select(x => x.GetAttribute("href")) 112 | .ToList(); 113 | 114 | return new Tuple>, List>(tuples, hrefs); 115 | }).ToArray(); 116 | 117 | foreach(var (stringTuples, hrefs) in tdContent) 118 | { 119 | 120 | var category = stringTuples.FindValue("category").Replace(" /", string.Empty); 121 | var title = stringTuples.FindValue("title").TrimEnd(); 122 | 123 | var info = stringTuples.FindValue("info"); 124 | if (!string.IsNullOrEmpty(info)) 125 | { 126 | title += $" [{info}]"; 127 | } 128 | 129 | var author = stringTuples.FindValue("author").Replace("/ ", string.Empty); 130 | var date = DateTime.Now; 131 | var recommend = stringTuples.FindValue("count").ToIntRegex(); 132 | 133 | var href = UrlCompositeHref(hrefs[0]); 134 | 135 | _ = OnCrawlData(new CrawlingData 136 | { 137 | Type = Source.Type, 138 | BoardId = Source.BoardId, 139 | BoardName = Source.Name, 140 | Category = category, 141 | Title = title.Substring("\t"), 142 | Author = author, 143 | Recommend = recommend, 144 | DateTime = date, 145 | Href = href, 146 | SourceId = Source.Id 147 | }); 148 | } 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/HumorUnivCrawler.cs: -------------------------------------------------------------------------------- 1 | using AngleSharp; 2 | using EzAspDotNet.Util; 3 | using MongoDB.Driver; 4 | using Serilog; 5 | using System; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using AngleSharp.Dom; 9 | using WebCrawler.Models; 10 | 11 | namespace WebCrawler.Crawler 12 | { 13 | public class HumorUnivCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 14 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"http://web.humoruniv.com/board/humor/list.html?table=", source) 15 | { 16 | protected override string UrlComposite(int page) 17 | { 18 | return page <= 1 ? $"{UrlBase}{Source.BoardId}" : $"{UrlBase}{Source.BoardId}&pg={page - 1}"; 19 | } 20 | 21 | protected override string UrlCompositeHref(string href) 22 | { 23 | return UrlBase.CutAndComposite("/", 0, 5, "/" + href); 24 | } 25 | 26 | protected override void OnPageCrawl(IDocument document) 27 | { 28 | if (document.Head.QuerySelector("meta")?.GetAttribute("http-equiv") == "refresh") 29 | { 30 | Log.Error($"http-equip refresh. {UrlComposite(1)}.\n"); 31 | return; 32 | } 33 | 34 | var tdContent = document.QuerySelectorAll("tr td") 35 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.StartsWith("li_")) 36 | .ToArray(); 37 | 38 | if (!tdContent.Any()) 39 | { 40 | Log.Error($"Parsing Failed DOM. Not has tdContent {UrlComposite(1)}.\n"); 41 | return; 42 | } 43 | 44 | const int thLength = 7; 45 | var thContent = tdContent.Take(thLength); 46 | tdContent = tdContent.Skip(thLength).ToArray(); 47 | 48 | for(var n = 0; n < tdContent.Length / thLength; ++n) 49 | { 50 | var cursor = n * thLength; 51 | 52 | var originTitle = tdContent[cursor + 1].QuerySelector("a").TextContent.Trim(); 53 | 54 | var title = originTitle.Substring("\n"); 55 | var author = tdContent[cursor + 2].TextContent.Trim(); 56 | var date = DateTime.Parse(tdContent[cursor + 3].TextContent.Trim()); 57 | var count = tdContent[cursor + 4].TextContent.Trim().ToInt(); 58 | var recommend = tdContent[cursor + 5].TextContent.Trim().ToInt(); 59 | var notRecommend = tdContent[cursor + 6].TextContent.Trim().ToInt(); 60 | 61 | var href = UrlCompositeHref(tdContent[cursor + 1].QuerySelector("a").GetAttribute("href")); 62 | 63 | _ = OnCrawlData(new CrawlingData 64 | { 65 | Type = Source.Type, 66 | BoardId = Source.BoardId, 67 | BoardName = Source.Name, 68 | Title = title, 69 | Author = author, 70 | Recommend = recommend - notRecommend, 71 | Count = count, 72 | DateTime = date, 73 | Href = href, 74 | SourceId = Source.Id 75 | }); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/InvenNewsCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using AngleSharp.Dom; 8 | using WebCrawler.Models; 9 | 10 | namespace WebCrawler.Crawler 11 | { 12 | public class InvenNewsCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 13 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"http://www.inven.co.kr/webzine/news/", source) 14 | { 15 | protected override string UrlComposite(int page) 16 | { 17 | return $"{UrlBase}?{Source.BoardId}&page={page}"; 18 | } 19 | 20 | protected override void OnPageCrawl(IDocument document) 21 | { 22 | var tdContents = document.QuerySelectorAll("tbody tr") 23 | .Select(x => 24 | { 25 | var stringTuples = x.QuerySelectorAll("span") 26 | .Where(x => x.ClassName != "category") 27 | .Select(y => new Tuple(y.ClassName, y.TextContent.Trim())).ToList(); 28 | 29 | var hrefs = x.QuerySelectorAll("a") 30 | .Select(x => x.GetAttribute("href")) 31 | .ToList(); 32 | 33 | return new Tuple>, List>(stringTuples, hrefs); 34 | }) 35 | .ToArray(); 36 | 37 | foreach(var (stringTuples, hrefs) in tdContents) 38 | { 39 | var count = stringTuples.FindValue("cmtnum"); 40 | 41 | var originTitle = stringTuples.FindValue("title"); 42 | 43 | var infos = stringTuples.FindValue("info").Split("|"); 44 | var title = string.IsNullOrEmpty(count) ? originTitle : originTitle.Substring(count); 45 | var category = infos[0].Substring("\n"); 46 | var author = infos.Count() <= 2 ? "" : infos[1]; 47 | var date = infos.Count() <= 2 ? DateTime.Parse(infos[1]) : DateTime.Parse(infos[2]); 48 | var recommend = string.IsNullOrEmpty(count) ? 0 : count.ToIntRegex(); 49 | 50 | var href = hrefs[0]; 51 | 52 | _ = OnCrawlData(new CrawlingData 53 | { 54 | Type = Source.Type, 55 | BoardId = Source.BoardId, 56 | BoardName = Source.Name, 57 | Title = title, 58 | Category = category, 59 | Author = author, 60 | Recommend = recommend, 61 | DateTime = date, 62 | Href = href, 63 | SourceId = Source.Id 64 | }); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/ItcmCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using AngleSharp.Dom; 8 | using WebCrawler.Models; 9 | 10 | namespace WebCrawler.Crawler 11 | { 12 | public class ItcmCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 13 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"http://itcm.co.kr/index.php?mid=", source) 14 | { 15 | protected override string UrlComposite(int page) 16 | { 17 | return $"{UrlBase}{Source.BoardId}&page={page}"; 18 | } 19 | 20 | protected override void OnPageCrawl(IDocument document) 21 | { 22 | var tdContents = document.QuerySelectorAll("tbody tr") 23 | .Where(x => string.IsNullOrEmpty(x.ClassName) || x.ClassName != "notice") 24 | .Select(x => 25 | { 26 | var stringTuples = x.QuerySelectorAll("td") 27 | .Select(y => 28 | { 29 | var text = y.TextContent.Trim(); 30 | if (string.IsNullOrEmpty(text)) 31 | { 32 | text = y.QuerySelectorAll("img") 33 | .Where(x => x.GetAttribute("src") != null) 34 | .Select(x => x.GetAttribute("title")).LastOrDefault(); 35 | 36 | // LastOrDefault인 이유는 Author 부분이 First쪽이 레벨이기 때문 37 | } 38 | 39 | return new Tuple(y.ClassName, text); 40 | }).ToList(); 41 | 42 | var hrefs = x.QuerySelectorAll("a") 43 | .Select(x => x.GetAttribute("href")) 44 | .ToList(); 45 | 46 | return new Tuple>, List>(stringTuples, hrefs); 47 | }) 48 | .ToArray(); 49 | 50 | foreach(var (stringTuples, hrefs) in tdContents) 51 | { 52 | var title = stringTuples.FindValue("title"); 53 | title = title.Substring("\n"); 54 | 55 | var category = stringTuples.FindValue("cate"); 56 | var author = stringTuples.FindValue("author"); 57 | var date = DateTime.Parse(stringTuples.FindValue("time")); 58 | if (date > DateTime.Now) // 12월 표기가 12-15라서 파싱되서 연초에는 꼬여서 예외처리 59 | { 60 | date = date.AddYears(-1); 61 | } 62 | 63 | var count = stringTuples[7].Item2.ToInt(); 64 | var recommend = stringTuples[8].Item2.ToInt(); 65 | 66 | var href = hrefs[0]; 67 | 68 | _ = OnCrawlData(new CrawlingData 69 | { 70 | Type = Source.Type, 71 | BoardId = Source.BoardId, 72 | BoardName = Source.Name, 73 | Title = title, 74 | Category = category, 75 | Author = author, 76 | Count = count, 77 | Recommend = recommend, 78 | DateTime = date, 79 | Href = href, 80 | SourceId = Source.Id 81 | }); 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/PpomppuCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using Serilog; 4 | using System; 5 | using System.Globalization; 6 | using System.Linq; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using AngleSharp.Dom; 10 | using System.Text; 11 | using WebCrawler.Models; 12 | 13 | namespace WebCrawler.Crawler 14 | { 15 | public class PpomppuCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 16 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"https://www.ppomppu.co.kr/zboard/zboard.php", source) 17 | { 18 | protected override string UrlComposite(int page) 19 | { 20 | return $"{UrlBase}?id={Source.BoardId}&page={page}"; 21 | } 22 | 23 | protected override string UrlCompositeHref(string href) 24 | { 25 | return UrlBase.CutAndComposite("/", 0, 4, href); 26 | } 27 | 28 | protected override void OnPageCrawl(IDocument document) 29 | { 30 | var cultureInfo = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); 31 | var calendar = cultureInfo.Calendar; 32 | calendar.TwoDigitYearMax = DateTime.Now.Year + 30; 33 | cultureInfo.DateTimeFormat.Calendar = calendar; 34 | 35 | var thContent = document.QuerySelectorAll("tbody tr") 36 | .Where(x => x.Id == "headNotice" || x.ClassName == "title_bg") 37 | .Select(x => x.QuerySelectorAll("span, font")) 38 | .SelectMany(x => x.Select(y => y.TextContent.Trim())) 39 | .ToArray(); 40 | 41 | var tdContent = document.QuerySelectorAll("tbody tr") 42 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.StartsWith("baseList")) 43 | .Select(x => x.QuerySelectorAll("td").Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.StartsWith("baseList-space"))) 44 | .SelectMany(x => x.Select(y => 45 | { 46 | var text = y.TextContent.Trim(); 47 | if (string.IsNullOrEmpty(text)) 48 | { 49 | text = y.QuerySelector("img")?.GetAttribute("alt"); 50 | } 51 | if (y.QuerySelector("font") != null) 52 | { 53 | text = y.QuerySelector("font").TextContent.Trim(); 54 | } 55 | 56 | return text; 57 | })) 58 | .ToArray(); 59 | 60 | var tdHref = document.QuerySelectorAll("tbody tr") 61 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.StartsWith("baseList")) 62 | .Select(x => x.QuerySelectorAll("td a")) 63 | .SelectMany(x => x.Select(y => y.GetAttribute("href"))) 64 | .Where(x => x != "#") 65 | .ToArray(); 66 | 67 | if (thContent.Length == 0 || tdContent.Length == 0) 68 | { 69 | Log.Error("Parsing Failed DOM. Not has thContent or tdContent {UrlComposite}", UrlComposite(1)); 70 | return; 71 | } 72 | 73 | for(var n = 0; n < tdContent.Length / thContent.Length; ++n) 74 | { 75 | var cursor = n * thContent.Length; 76 | 77 | if (!int.TryParse(tdContent[cursor + 0], out var id)) 78 | { 79 | return; 80 | } 81 | 82 | var title = tdContent[cursor + 1].Split(["\r\n", "\n", "\r"], StringSplitOptions.None)[0].Trim(); 83 | var author = tdContent[cursor + 2]; 84 | var dateTimeStr = tdContent[cursor + 3]; 85 | var date = dateTimeStr.Contains('/') ? DateTime.ParseExact(dateTimeStr, "yy/MM/dd", cultureInfo) : DateTime.Parse(dateTimeStr); 86 | 87 | var str = tdContent[cursor + 4]; 88 | var recommend = string.IsNullOrEmpty(str) ? 0 : str.Split(" - ")[0].ToInt(); 89 | 90 | var count = tdContent[cursor + 5].ToInt(); 91 | 92 | var href = UrlCompositeHref("/" + tdHref[n]); 93 | 94 | _ = OnCrawlData(new CrawlingData 95 | { 96 | Type = Source.Type, 97 | BoardId = Source.BoardId, 98 | BoardName = Source.Name, 99 | RowId = id, 100 | Title = title, 101 | Author = author, 102 | Recommend = recommend, 103 | Count = count, 104 | DateTime = date, 105 | Href = href, 106 | SourceId = Source.Id 107 | }); 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/RuliwebCrawler.cs: -------------------------------------------------------------------------------- 1 | using AngleSharp.Dom; 2 | using EzAspDotNet.Util; 3 | using MongoDB.Driver; 4 | using Serilog; 5 | using System; 6 | using System.Globalization; 7 | using System.Linq; 8 | using System.Text.RegularExpressions; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using WebCrawler.Models; 12 | 13 | namespace WebCrawler.Crawler 14 | { 15 | public partial class RuliwebCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 16 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"https://bbs.ruliweb.com/{source.BoardId}", source) 17 | { 18 | protected override string UrlComposite(int page) 19 | { 20 | return $"{UrlBase}?page={page}"; 21 | } 22 | 23 | protected override void OnPageCrawl(IDocument document) 24 | { 25 | var cultureInfo = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); 26 | var calendar = cultureInfo.Calendar; 27 | calendar.TwoDigitYearMax = DateTime.Now.Year + 30; 28 | cultureInfo.DateTimeFormat.Calendar = calendar; 29 | 30 | var bestBody = document.GetElementById("best_body"); 31 | if (bestBody != null) 32 | { 33 | var rows = bestBody.QuerySelectorAll("tr") 34 | .Where(x => x.ClassName.Contains("table_body")) 35 | .Select(x => x.TextContent.Trim()) 36 | .ToList(); 37 | 38 | var tdContent = bestBody.QuerySelectorAll("td") 39 | .Select(cell => 40 | { 41 | var cleanHtml = Regex.Replace(cell.InnerHtml, 42 | @"]*(class\s*=\s*[""'][^""']*num_reply[^""']*[""']|style\s*=\s*[""'][^""']*(width\s*:\s*20px;).*?[""'])[^>]*?>.*?", 43 | "", 44 | RegexOptions.IgnoreCase | RegexOptions.Singleline); 45 | 46 | cleanHtml = Regex.Replace(cleanHtml, @"[\n\t]", ""); 47 | cleanHtml = Regex.Replace(cleanHtml, @" {2,}", " "); 48 | cleanHtml = cleanHtml.Trim(); 49 | 50 | // 태그를 제외한 순수 텍스트 추출 51 | var textContent = Regex.Replace(cleanHtml, @"<[^>]+>", "").Trim(); 52 | 53 | return string.IsNullOrWhiteSpace(textContent) ? "" : textContent; 54 | }) 55 | .ToArray(); 56 | 57 | var tdHref = document.QuerySelectorAll("tbody tr") 58 | .Select(x => x.QuerySelectorAll("td")) 59 | .SelectMany(x => x.Where(y => y.QuerySelector("a") != null) 60 | .Select(y => y.QuerySelector("a").GetAttribute("href"))) 61 | .ToArray(); 62 | 63 | if (rows.Count == 0 || tdContent.Length == 0) 64 | { 65 | Log.Error("Parsing Failed DOM. Not has rows or tdContent {UrlComposite}", UrlComposite(1)); 66 | return; 67 | } 68 | 69 | var colCount = tdContent.Length / rows.Count; 70 | 71 | for(var n = 0; n < rows.Count; ++n) 72 | { 73 | var cursor = n * colCount; 74 | var id = tdContent[cursor + 0].ToIntRegex(); 75 | 76 | var title = tdContent[cursor + 1]; 77 | 78 | var author = tdContent[cursor + 2]; 79 | var recommend = tdContent[cursor + 3].ToIntRegex(); 80 | var count = tdContent[cursor + 4].ToIntRegex(); 81 | 82 | var dateTimeStr = tdContent[cursor + 5].Replace("날짜 ", string.Empty); 83 | DateTime? date; 84 | if (dateTimeStr.Contains('.')) 85 | { 86 | date = dateTimeStr.IndexOf('.') >= 4 ? 87 | DateTime.ParseExact(dateTimeStr, "yyyy.MM.dd", cultureInfo) : 88 | DateTime.ParseExact(dateTimeStr, "yy.MM.dd", cultureInfo); 89 | } 90 | else 91 | { 92 | date = DateTime.Parse(dateTimeStr); 93 | } 94 | 95 | var href = tdHref[n]; 96 | 97 | _ = OnCrawlData(new CrawlingData 98 | { 99 | Type = Source.Type, 100 | BoardId = Source.BoardId, 101 | BoardName = Source.Name, 102 | RowId = id, 103 | Title = title, 104 | Author = author, 105 | Recommend = recommend, 106 | Count = count, 107 | DateTime = date.GetValueOrDefault(DateTime.Now), 108 | Href = Host + href, 109 | SourceId = Source.Id 110 | }); 111 | } 112 | } 113 | else 114 | { 115 | var thContent = document.QuerySelectorAll("thead tr th") 116 | .Select(x => x.TextContent.Trim()) 117 | .ToList(); 118 | 119 | var tdContent = document.QuerySelectorAll("tbody tr") 120 | .Where(x => x.ClassName.Contains("table_body") && x.ClassName.Contains("blocktarget") && !string.IsNullOrEmpty(x.TextContent)) 121 | .SelectMany(x => x.QuerySelectorAll("td") 122 | .Select(cell => 123 | { 124 | // InnerHtml에서 ... 제거 125 | var cleanHtml = Regex.Replace(cell.InnerHtml, @"]*?num_reply[^>]*?>.*?", "", RegexOptions.IgnoreCase); 126 | 127 | // 태그를 제외한 순수 텍스트 추출 128 | var textContent = Regex.Replace(cleanHtml, @"<[^>]+>", "").Trim(); 129 | 130 | return string.IsNullOrWhiteSpace(textContent) ? "" : textContent; 131 | })) 132 | .ToArray(); 133 | 134 | var tdHref = document.QuerySelectorAll("tbody tr") 135 | .Where(x => x.ClassName.Contains("table_body") && x.ClassName.Contains("blocktarget")) 136 | .Select(x => x.QuerySelectorAll("td")) 137 | .SelectMany(x => x.Where(y => y.ClassName == "subject" && y.QuerySelector("a") != null) 138 | .Select(y => y.QuerySelector("a").GetAttribute("href"))) 139 | .Where(x => x.StartsWith("http")) 140 | .ToArray(); 141 | 142 | if (thContent.Count == 0 || tdContent.Length == 0) 143 | { 144 | Log.Error("Parsing Failed DOM. Not has thContent or tdContent {UrlComposite}", UrlComposite(1)); 145 | return; 146 | } 147 | 148 | for(var n = 0; n < tdContent.Length / thContent.Count; ++n) 149 | { 150 | var cursor = n * thContent.Count; 151 | var id = tdContent.GetValue(thContent, "ID", cursor).ToIntRegex(); 152 | var category = tdContent.GetValue(thContent, "구분", cursor); 153 | if (string.IsNullOrEmpty(category)) 154 | { 155 | category = tdContent.GetValue(thContent, "게시판", cursor); 156 | } 157 | 158 | var title = tdContent.GetValue(thContent, "제목", cursor).Substring("\n"); 159 | var author = tdContent.GetValue(thContent, "글쓴이", cursor); 160 | var recommend = tdContent.GetValue(thContent, "추천", cursor).ToIntNullable(); 161 | var count = tdContent.GetValue(thContent, "조회", cursor).ToInt(); 162 | 163 | var dateTimeStr = tdContent.GetValue(thContent, "날짜", cursor); 164 | DateTime? date; 165 | if (dateTimeStr.Contains('.')) 166 | { 167 | date = dateTimeStr.IndexOf('.') >= 4 ? 168 | DateTime.ParseExact(dateTimeStr, "yyyy.MM.dd", cultureInfo) : 169 | DateTime.ParseExact(dateTimeStr, "yy.MM.dd", cultureInfo); 170 | } 171 | else 172 | { 173 | date = DateTime.Parse(dateTimeStr); 174 | } 175 | 176 | var href = tdHref[n].Split("?")[0]; 177 | 178 | _ = OnCrawlData(new CrawlingData 179 | { 180 | Type = Source.Type, 181 | BoardId = Source.BoardId, 182 | BoardName = Source.Name, 183 | Category = category, 184 | Title = title, 185 | Author = author, 186 | Recommend = recommend.GetValueOrDefault(0), 187 | Count = count, 188 | DateTime = date.GetValueOrDefault(DateTime.Now), 189 | RowId = id, 190 | Href = href, 191 | SourceId = Source.Id 192 | }); 193 | } 194 | } 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/SlrclubCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using Serilog; 4 | using System; 5 | using System.Linq; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using AngleSharp.Dom; 9 | using WebCrawler.Models; 10 | 11 | namespace WebCrawler.Crawler 12 | { 13 | public class SlrclubCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 14 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"http://www.slrclub.com/bbs/zboard.php", source) 15 | { 16 | private static int? LatestPage { get; set; } 17 | 18 | protected override string UrlComposite(int page) 19 | { 20 | return $"{UrlBase}?id={Source.BoardId}&page={LatestPage - page - 1}"; 21 | } 22 | 23 | public override async Task RunAsync() 24 | { 25 | var pageInfoCrawler = new SlrclubPageInfoCrawler(null, null, Source); 26 | await pageInfoCrawler.RunAsync(); 27 | 28 | if (SlrclubPageInfoCrawler.LatestPage.HasValue) 29 | { 30 | LatestPage = SlrclubPageInfoCrawler.LatestPage; 31 | } 32 | 33 | if (!LatestPage.HasValue) 34 | { 35 | Log.Logger.Error("Not Found PageInfo Data {UrlBase}", UrlBase); 36 | return; 37 | } 38 | 39 | for (var page = Source.PageMin; page <= Source.PageMax; ++page) 40 | { 41 | await ExecuteAsync(page); 42 | Thread.Sleep(Source.Interval); 43 | } 44 | } 45 | 46 | protected override void OnPageCrawl(IDocument document) 47 | { 48 | var thContent = document.QuerySelectorAll("thead tr th") 49 | .Select(x => x.TextContent.Trim()).ToArray(); 50 | 51 | var tdContent = document.QuerySelectorAll("tbody tr td") 52 | .Select(x => x.QuerySelector("a") != null ? x.QuerySelector("a").TextContent.Trim() : x.TextContent.Trim()) 53 | .ToArray(); 54 | 55 | var tdHref = document.QuerySelectorAll("tbody tr td") 56 | .Where(x => !string.IsNullOrEmpty(x.ClassName) && x.ClassName.Contains("sbj")) 57 | .Select(x => x.QuerySelector("a").GetAttribute("href")) 58 | .ToArray(); 59 | 60 | if (thContent.Length == 0 || tdContent.Length == 0) 61 | { 62 | Log.Error("Parsing Failed DOM. Not has thContent or tdContent {UrlComposite}", UrlComposite(1)); 63 | return; 64 | } 65 | 66 | for(var n = 0; n < tdContent.Length / thContent.Length; ++n) 67 | { 68 | var cursor = n * thContent.Length; 69 | var id = tdContent[cursor + 0].ToInt(); 70 | var title = tdContent[cursor + 1]; 71 | var author = tdContent[cursor + 2]; 72 | var date = DateTime.Parse(tdContent[cursor + 3]); 73 | var recommend = tdContent[cursor + 4].ToInt(); 74 | var count = tdContent[cursor + 5].ToInt(); 75 | 76 | var href = UrlCompositeHref(tdHref[n]); 77 | 78 | _ = OnCrawlData(new CrawlingData 79 | { 80 | Type = Source.Type, 81 | BoardId = Source.BoardId, 82 | BoardName = Source.Name, 83 | RowId = id, 84 | Title = title, 85 | Author = author, 86 | Recommend = recommend, 87 | Count = count, 88 | DateTime = date, 89 | Href = href, 90 | SourceId = Source.Id 91 | }); 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/SlrclubPageInfoCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AngleSharp.Dom; 6 | using WebCrawler.Models; 7 | 8 | namespace WebCrawler.Crawler 9 | { 10 | public class SlrclubPageInfoCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 11 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"http://www.slrclub.com/bbs/zboard.php", source) 12 | { 13 | public static int? LatestPage { get; private set; } 14 | 15 | protected override string UrlComposite(int page) 16 | { 17 | return $"{UrlBase}?id={Source.BoardId}&page={page}"; 18 | } 19 | 20 | public override async Task RunAsync() 21 | { 22 | // 전체 페이지를 알아오기 위한 SlrClub용 우회이므로, 그냥 1페이지를 호출한다. 23 | await ExecuteAsync(1); 24 | } 25 | 26 | protected override void OnPageCrawl(IDocument document) 27 | { 28 | var tdContent = document.QuerySelectorAll("tbody tr td table tbody tr td span").Select(x => x.TextContent.Trim()).ToArray(); 29 | if (tdContent.Length == 0) 30 | { 31 | return; 32 | } 33 | 34 | var latest = tdContent.LastOrDefault(); 35 | LatestPage = string.IsNullOrEmpty(latest) ? (int?)null : latest.ToInt(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /WebCrawler/Crawler/TodayhumorCrawler.cs: -------------------------------------------------------------------------------- 1 | using EzAspDotNet.Util; 2 | using MongoDB.Driver; 3 | using Serilog; 4 | using System; 5 | using System.Globalization; 6 | using System.Linq; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using AngleSharp.Dom; 10 | using WebCrawler.Models; 11 | 12 | namespace WebCrawler.Crawler 13 | { 14 | public class TodayhumorCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Source source) 15 | : CrawlerBase(onCrawlDataDelegate, mongoDb, $"http://www.todayhumor.co.kr/board/list.php", source) 16 | { 17 | protected override string UrlComposite(int page) 18 | { 19 | return $"{UrlBase}?table={Source.BoardId}&page={page}"; 20 | } 21 | 22 | protected override void OnPageCrawl(IDocument document) 23 | { 24 | var thContent = document.QuerySelectorAll("thead tr th") 25 | .Select(x => x.TextContent.Trim()) 26 | .ToArray(); 27 | 28 | var tdContent = document.QuerySelectorAll("tbody tr") 29 | .Where(x => x.ClassName != null && x.ClassName.StartsWith("view list_tr_")) 30 | .Select(x => x.QuerySelectorAll("td")) 31 | .SelectMany(x => x.Select(y => y.QuerySelector("a") != null ? y.QuerySelector("a").TextContent.Trim() : y.TextContent.Trim())) 32 | .ToArray(); 33 | 34 | var tdHref = document.QuerySelectorAll("tbody tr td") 35 | .Where(x => x.ClassName == ("subject")) 36 | .Select(x => x.QuerySelector("a").GetAttribute("href")) 37 | .ToArray(); 38 | 39 | if (!thContent.Any() || !tdContent.Any()) 40 | { 41 | Log.Error("Parsing Failed DOM. Not has thContent or tdContent {UrlComposite}", UrlComposite(1)); 42 | return; 43 | } 44 | 45 | var cultureInfo = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); 46 | var calendar = cultureInfo.Calendar; 47 | calendar.TwoDigitYearMax = DateTime.Now.Year + 30; 48 | cultureInfo.DateTimeFormat.Calendar = calendar; 49 | 50 | for(var n = 0; n < tdContent.Length / thContent.Length; ++n) 51 | { 52 | var cursor = n * thContent.Length; 53 | var id = tdContent[cursor + 0].ToIntRegex(); 54 | var title = tdContent[cursor + 2]; 55 | var author = tdContent[cursor + 3]; 56 | var date = DateTime.ParseExact(tdContent[cursor + 4], "yy/MM/dd HH:mm", cultureInfo); 57 | var count = tdContent[cursor + 5].ToInt(); 58 | var recommend = tdContent[cursor + 6].Split("/")[0].ToIntRegex(); 59 | 60 | var href = UrlCompositeHref(tdHref[n]); 61 | 62 | _ = OnCrawlData(new CrawlingData 63 | { 64 | Type = Source.Type, 65 | BoardId = Source.BoardId, 66 | BoardName = Source.Name, 67 | RowId = id, 68 | Title = title, 69 | Author = author, 70 | Recommend = recommend, 71 | Count = count, 72 | DateTime = date, 73 | Href = href, 74 | SourceId = Source.Id 75 | }); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /WebCrawler/Models/CrawlingData.cs: -------------------------------------------------------------------------------- 1 | using EzMongoDb.Models; 2 | using MongoDB.Bson; 3 | using MongoDB.Bson.Serialization.Attributes; 4 | using System; 5 | using WebCrawler.Code; 6 | 7 | namespace WebCrawler.Models 8 | { 9 | public class CrawlingData : MongoDbHeader 10 | { 11 | [BsonRepresentation(BsonType.String)] 12 | public CrawlingType Type { get; set; } 13 | 14 | public string BoardId { get; set; } 15 | 16 | public string BoardName { get; set; } 17 | 18 | public string Author { get; set; } 19 | 20 | public string SourceId { get; set; } 21 | 22 | public string Href { get; set; } 23 | 24 | public string Category { get; set; } 25 | 26 | public int Count { get; set; } 27 | 28 | public int Recommend { get; set; } 29 | 30 | public string Title { get; set; } 31 | 32 | public DateTime DateTime { get; set; } 33 | 34 | public long? RowId { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WebCrawler/Models/Source.cs: -------------------------------------------------------------------------------- 1 | using EzMongoDb.Models; 2 | using MongoDB.Bson; 3 | using MongoDB.Bson.Serialization.Attributes; 4 | using WebCrawler.Code; 5 | 6 | namespace WebCrawler.Models 7 | { 8 | public class Source : MongoDbHeader 9 | { 10 | public string BoardId { get; set; } 11 | 12 | [BsonRepresentation(BsonType.String)] 13 | public CrawlingType Type { get; set; } 14 | 15 | public string Name { get; set; } 16 | 17 | public int PageMin { get; set; } = 1; 18 | 19 | public int PageMax { get; set; } = 5; 20 | 21 | public int Interval { get; set; } = 1; 22 | 23 | public bool Switch { get; set; } = true; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /WebCrawler/WebCrawler.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net9.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elky84/web-crawler/13d7a6514751dace84eaef6ae851c9581befb136/sample1.png -------------------------------------------------------------------------------- /web-crawler.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebCrawler", "WebCrawler\WebCrawler.csproj", "{10E80C77-1D3C-497E-8F58-87D20A929FB0}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{65749314-33BD-4863-B270-4E876AB0CB73}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {10E80C77-1D3C-497E-8F58-87D20A929FB0} = {10E80C77-1D3C-497E-8F58-87D20A929FB0} 11 | EndProjectSection 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{4F67F7DB-B3C6-4716-8BA7-C466C84872B8}" 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cli", "Cli", "{583BEDFA-070B-4B5D-A9B2-A74A51FCB9DA}" 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{F02D5115-351B-4FAF-B7F6-E536598D4458}" 18 | ProjectSection(ProjectDependencies) = postProject 19 | {10E80C77-1D3C-497E-8F58-87D20A929FB0} = {10E80C77-1D3C-497E-8F58-87D20A929FB0} 20 | EndProjectSection 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{20930D64-928C-46EE-9E1F-26097F23ECFD}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cli", "Cli\Cli.csproj", "{4E456D36-96BC-436D-A991-8A77B2FFDC08}" 25 | EndProject 26 | Global 27 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 28 | Debug|Any CPU = Debug|Any CPU 29 | Release|Any CPU = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 32 | {10E80C77-1D3C-497E-8F58-87D20A929FB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {10E80C77-1D3C-497E-8F58-87D20A929FB0}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {10E80C77-1D3C-497E-8F58-87D20A929FB0}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {10E80C77-1D3C-497E-8F58-87D20A929FB0}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {65749314-33BD-4863-B270-4E876AB0CB73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {65749314-33BD-4863-B270-4E876AB0CB73}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {65749314-33BD-4863-B270-4E876AB0CB73}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {65749314-33BD-4863-B270-4E876AB0CB73}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {F02D5115-351B-4FAF-B7F6-E536598D4458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {F02D5115-351B-4FAF-B7F6-E536598D4458}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {F02D5115-351B-4FAF-B7F6-E536598D4458}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {F02D5115-351B-4FAF-B7F6-E536598D4458}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {4E456D36-96BC-436D-A991-8A77B2FFDC08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {4E456D36-96BC-436D-A991-8A77B2FFDC08}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {4E456D36-96BC-436D-A991-8A77B2FFDC08}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {4E456D36-96BC-436D-A991-8A77B2FFDC08}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | GlobalSection(NestedProjects) = preSolution 53 | {10E80C77-1D3C-497E-8F58-87D20A929FB0} = {4F67F7DB-B3C6-4716-8BA7-C466C84872B8} 54 | {F02D5115-351B-4FAF-B7F6-E536598D4458} = {20930D64-928C-46EE-9E1F-26097F23ECFD} 55 | {4E456D36-96BC-436D-A991-8A77B2FFDC08} = {583BEDFA-070B-4B5D-A9B2-A74A51FCB9DA} 56 | EndGlobalSection 57 | GlobalSection(ExtensibilityGlobals) = postSolution 58 | SolutionGuid = {B77D2EA3-80ED-4BD2-B5D1-4343DE6C4F57} 59 | EndGlobalSection 60 | EndGlobal 61 | --------------------------------------------------------------------------------