Commit Graph
28 Commits
Author SHA1 Message Date
zheng elendil 1d0743da36 Fix Spider base class null context issue and remove deprecated UnitTest1 2026-03-29 09:26:38 +08:00
zheng elendil eb15a3afb5 Add Fluent API unit tests and restore .NET 10.0 target
- Changed NScrapy.Core target framework from net8.0 back to net10.0
- Added NScrapy.Core project reference to NScrapy.Test
- Created FluentApiTests.cs with the following test cases:
  - TestSpiderBuilder_CanCreateSpiderWithName
  - TestSpiderBuilder_BuildCreatesSpider
  - TestSpiderBuilder_SetsStartUrls
  - TestSpiderBuilder_AddsPipeline
  - TestDistributedBuilder_SetsRedisConfig
  - TestSpiderOptions_DefaultValues
  - TestDistributedBuilder_Chaining
  - TestSpiderBuilder_ConfiguresOptions
- Added helper classes TestItem and TestPipeline for testing pipelines
2026-03-28 22:30:44 +08:00
Sam (OpenClaw) 44a6df9804 Upgrade .NET Core 2.0 → .NET 10, add LianjiaHouseSpider demo
## Major Changes

- Upgrade all 9 projects from netcoreapp2.0 to net10.0
- Update NuGet packages to latest compatible versions:
  - HtmlAgilityPack → 1.11.61
  - log4net → 2.0.17
  - Microsoft.Extensions.Configuration* → 8.0.0
  - Newtonsoft.Json → 13.0.3
  - StackExchange.Redis → 2.7.33
  - MongoDB.Driver → 2.25.0
  - Microsoft.NET.Test.Sdk → 17.9.0, MSTest → 3.2.0
- Remove ZooKeeperNetEx (no .NET 8/10 compatible version)
- Remove HtmlAgilityPack.CssSelectors.NetCore → replaced with Fizzler.Systems.HtmlAgilityPack
- Exclude ZooKeeper-dependent files: ZookeeperConfigProvider, ConfigProviderFactory, DefaultConfigProvider
- Add .gitignore
- Fix source code API changes from package upgrades (QuerySelectorAll, etc.)

## New Demo Project

- NScrapy.Demo: LianjiaHouseSpider - crawls Beijing rental listings
  - Runs in InMemory mode (no ZooKeeper/Redis required)
  - Outputs results to CSV
  - Demonstrates NScrapy framework usage
2026-03-28 20:56:20 +08:00
Elendil 46086ffaf9 ConfigProvider update
Create a ConifgProviderFactory so thay we can get ConfigProvider from a single point
Also enhenced the logic of refresh config, right now when zookeeper watcher dected the config is changed
NScrapy will update its context, and during that time, NScrapy will lock the access to the Connection of Redis
2018-07-04 23:31:44 +08:00
Elendil 5a0ff77c8c ZKConfigProvider v0.1 2018-07-04 00:11:40 +08:00
Elendil e4351fa803 Optimized ZKHelper
make create to be able to create node recursively from the path
2018-06-29 01:35:26 +08:00
Elendil 66275a5598 POC of Zookeeper .net Client
also intergrate with ZookeeperConfigProvider
to be honest Zookeeper api is so hard to understand, why it is designed in such way?
2018-06-28 00:24:12 +08:00
Elendil 723a51ea62 Init ConfigManagement Component
Will use Zookeeper to manager the config for every node
Also changed some methed name in old design for the purpose of align naming practice
2018-06-27 01:31:28 +08:00
Elendil 3622c13fea individual downloader shell will update its downloader status to Redis
This is for the purpose of web console displaying distributed downloader status in the new future
2018-05-31 23:42:04 +08:00
Elendil 2219a5f87d Enhenced the ItemPipeline Field Mapping Logic
we can use Lambda to pick a property for mapping, instead of type the Field name manually
2018-05-17 00:52:00 +08:00
Elendil 7c15c702c6 ItemPipeLine first version
Enable ItemPipeline function by setting the below appsetting.json setting
"Pipelines": [
      { "Pipeline": "NScrapy.Infra.Pipeline.MockPipeline" }
    ],
there is also a mock test case for ItemPipeline
2018-05-17 00:11:59 +08:00
Elendil 4afa454ebb Add support for xPathSelector
HtmlAgilityPack does not support extract attr directly, made some enhencement to xPathSelector so it can now directly extract attribute of html element like this
/html/body/div/div/div/div/ul/li[i/b="企"]/div/div/h3/a@href
2018-05-16 01:32:47 +08:00
Elendil 00f90d9492 Change the response from Topic to Queue so that multiple Spider won't process the same response duplicate
Add lock to response pick logic
2018-05-10 02:04:54 +08:00
Elendil 2ed341c009 Add Distributed Support for Spider
Still need some investigate against that if the spider will crawl the same page while there are multiple spider running
2018-05-09 01:30:43 +08:00
Elendil a47b109a2e Distributed Downloader Version 0.1
A big step for NScrayp, it can now utilize multiple Downloaders
Downloaders are now distributed to different process/machine, the connection
between Downloader and Spider is based on Scheduler, the scheduler distribute
Downloader task to different Downloader through Redis MQ
Details can be configed in appsetting.json
NScrapy still support single process mode, as long as we specify the run mode to InMemory
2018-05-06 22:57:39 +08:00
Elendil 46cf06b664 Create DownloaderShell Project to make Downloader Distributeable
Make a wrap of Downloader named DownloaderShell, so that it can handle
request sent from Redis, which is actually pushed in to the specific Queue defined in appsetting.json

Not finished yet
2018-05-04 00:26:46 +08:00
Elendil aa2cd8c5ba New Branch of Distributed Spider
using Redis as messagequeue service to distribute request to different distributed Downloader
the first commit of this branch finishes the Config part of RedisScheduler
Rewrite the Scheduler, now it is called InMemoryScheduler
IOC to get the Actual Scheduler from appsettings.json
Fix a bug of refresh the config file
2018-05-03 00:18:38 +08:00
Elendil d36d75558e Add mechanism to Exit a Crawl of a Spider and a Test Case for it
By checking if there is anymore Pending Request/Response in Queue and Running Downloader
NScrapy.Crawl would exit if no more pending Request/Response/RunningDownloader

Also add test case for this mechanism
2018-05-01 21:38:42 +08:00
Elendil 290d150b14 Bug Fix and UrlFilter Added
Fix the HttpHeaderMiddleware bug
Added UrlFilter with MD5 enhenced
Improved the sample Spider "JobSpider" so that it can now crawl all the .net postions posted at liepin.com
2018-04-28 01:17:08 +08:00
Elendil d299ff60f3 Bug Fix and Log Function
Added log4net at the bottom of the project, in NScrapyContext
Enhenced the Response.CssSelector so that we can select element based on a set of selector
This is very userful when the web page have tiny different between each page
2018-04-26 01:44:14 +08:00
Elendil 27f63d5040 Bug fix and add Test case for DownloaderMiddleware
Bug fix of DownloaderMiddleware loading
Add Test case of HttpUserAgentPoolMiddleware
2018-04-23 22:41:50 +08:00
Elendil 2d9542a252 Add advanced CssSelector
we can now use  ::attr(href) syntax to get values from html attribute
example:
SourceHTML:
<div class="job-info">
<h3 title="招聘销售总监">
	<a href="https://www.liepin.com/job/1913549323.shtml" data-promid="imscid=R000000075&amp;ckid=b6ab9f62c5abd657&amp;headckid=b6ab9f62c5abd657&amp;pageNo=0&amp;pageIdx0&amp;totalIdx=0&amp;sup=1&amp;d_pageSize=40&amp;siTag=aEPqOr56EDcL1HyFlajr3w%7EfA9rXquZc5IkJpXC-Ycixw&amp;d_headId=549281be67f4c28a83bd3d340965b270&amp;d_ckId=549281be67f4c28a83bd3d340965b270&amp;d_sfrom=search_fp&amp;d_curPage=0&amp;d_posi=0" target="_blank" onclick="tlog=window.tlog||[];tlog.push('c:w_sojob_jobclick_9')">
销售总监 </a>
</h3>
</div>

Selector:
Response.CssSelector(".job-info h3 a::attr(href)").Extract();
The above will get a IEnumerable<String> that only contains the href of the link in above SourceHTML
Response.CssSelector(".job-info h3 a::attr(href)").ExtractFirst();
The above code will get the first element as string from the CssSelector, here the value is
https://www.liepin.com/job/1913549323.shtml

::attr(text) will get the InnerText of the element
2018-04-20 01:23:44 +08:00
Elendil d25499879c Intergarated with HtmlAgilityPack.CssSelectors
Wrap the Css selected node into a IResponse again so that we can process in chain
NScrapy can now get url from response through regex and HtmlAgilityPack.CssSelectors
By getting the url, we can again send request and write call back function to get more data
2018-04-19 01:58:58 +08:00
Elendil 05368bee59 Optimized the Structure of the Entire Project
Involve HtmlAgilityPack and HtmlAgilityPack.CssSelector.NetCore in Infra
To help Getting element through CSS Selector
2018-04-18 22:12:37 +08:00
Elendil aaaefc49e9 Add HttpCompressionMiddleware to Infra in case the returned Content is Compressed 2018-04-15 22:09:38 +08:00
Elendil adc1044009 Add DownloaderMiddleware process logic and added a default DownloaderMiddleware
HttpHeaderMiddleware as a Default DownloaderMiddleware will set HttpRequest Header
based on the config in appsetting.json (AppSettings:HttpHeader section)
If specified node is not set in config file, Middleware will use its default value to fullfill the request header
2018-04-13 01:12:15 +08:00
Elendil 18c4dca3ab Created base structure of NScrapy Shell, Engine, Scheduler, Downloader
Engine:
1.Configurable in appsetting.json to choice a real engine or a mock engine for test
2.Listen to Item queue to handle the request sent by Scheduler
Shell:
1.Init Context for NScrapy to run
	1).Read Config
2.Get Spider through Spider Factory
Scheduler:
1.Send request to Queue which the engine is listening
Downloader
1.Init DownloaderPool
2.Asyncly Process all the incoming request by picking a Downloader from DownloaderPool
*Test Case update
EngineTest:Test if the message can be sent to MockEngine through Shell->Spider->Scheduler->Engine
ConstructDownloader:Test if DownloaderPool can work, if the Downloader can actually get response from Website
2018-04-12 00:27:39 +08:00
Elendil 318ae792bd Init checkin of NScrapy 2018-04-05 00:20:49 +08:00