using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using DataCollect.Model;
using HtmlAgilityPack;//引入插件
using Dapper;//引入插件
namespace DataCollect.UI
{
public partial class MainForm1 : DevExpress.XtraEditors.XtraForm
{
CancellationTokenSource cts = new CancellationTokenSource();
List<Job> list = new List<Job>();
public MainForm1()
{
InitializeComponent();
}
private void MainForm1_Load(object sender, EventArgs e)
{
}
private void simpleButton1_Click(object sender, EventArgs e)
{
//线程与线程之前不能直接访问(线程是独立的任务片段)
Task task1 = new Task(Collect);//创建一个线程任务
task1.Start();
}
/// <summary>
/// 数据采集
/// </summary>
private void Collect()
{
int index = 1;
int pageCount=0;
do
{
//HtmlAgilityPack.HtmlDocument htmlDocument=DataLoad(index);
var htmlDocument = DataLoad(index);
if (index == 1)
{
//根据查询节点信息,获取某个节点
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//input[@id='hidTotalPage']");//标答节点//根节点
pageCount = int.Parse(htmlNode.Attributes["value"].Valu
C# 网络爬虫
最新推荐文章于 2025-10-03 16:55:05 发布
本博客介绍了一个使用C#进行数据采集的项目,该项目从51job网站上抓取工作列表信息,并将数据存储到SQL Server数据库中。采集过程采用多线程并利用HtmlAgilityPack和Dapper插件解析网页,展示了如何处理线程间通信、数据持久化及UI更新。

最低0.47元/天 解锁文章
5170

被折叠的 条评论
为什么被折叠?



