html获取网站标题,批量获取网站标题

该博客介绍了一个C#程序,用于批量获取多个网站的标题。通过使用线程池和Http请求库,程序能高效地从指定网址列表中抓取每个网站的标题,并在界面上实时更新进度。此外,程序提供了暂停、继续和停止的功能,以及导出结果到txt文件的选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【实例简介】

批量获取网站的标题

【实例截图】

eaf220bf052ff07c01849e28e7b914a6.png

【核心代码】

using HttpCodeLib;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Net;

using System.Text;

using System.Text.RegularExpressions;

using System.Threading;

using System.Windows.Forms;

namespace 批量获取网站标题

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

protected List ItemsSource

{

get;

private set;

}

protected List CurrentCacheItemsSource

{

get;

private set;

}

private void button2_Click(object sender, EventArgs e)

{

stop = 0;

logg = 0;

if (listView1.Items.Count > 0)

{

button2.Enabled = false;

button5.Enabled = false;

button1.Enabled = false;

button3.Enabled = false;

button4.Enabled = false;

button6.Visible = true;

button7.Visible = true;

progressBar1.Value = 0;

progressBar1.Visible = true;

progressBar1.Maximum = listView1.Items.Count;

//ThreadPool.SetMaxThreads(20, 20);//允许线程池中运行最多 20 个线程

for (int i = 0; i < listView1.Items.Count&&stop==0; i )

{

Thread th = new Thread(get_biaoti);

th.IsBackground = true;

string url = listView1.Items[i].SubItems[1].Text;

List list = new List();

list.Add(i.ToString());

list.Add(url);

th.Start(list);//可以执行进程

thCount ;

while (thCount >= maxThCount||logg==1)

{

Thread.Sleep(10);

Application.DoEvents();

}

// ThreadPool.QueueUserWorkItem(new WaitCallback(get_biaoti), list);

}

}

}

int thCount = 0;

int maxThCount = 20;

int logg = 0;

int stop = 0;

///

/// 获取标题

///

/// 页面内容

private void get_biaoti(object obj)

{

int i = (int.Parse((obj as List)[0]));

string url = (obj as List)[1];

string res = string.Empty;

if (jiekou == 1)

{

//string

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值