国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net采集網(wǎng)頁圖片的具體方法

2024-07-10 12:45:21
字體:
供稿:網(wǎng)友
在網(wǎng)上找了下大多都是通過字符串操作找出img標(biāo)簽,這種方式操作起來比較麻煩,而且代碼看起來比較累。這里我用的方法是通過WebBrowser來加載一個頁面,然后HTMLDocument類來操作省去了字符串操作的步驟,直接調(diào)用GetElementsByTagName把所有圖片地址返回到一個HtmlElementCollection對象里。
代碼如下:
代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public class GatherPic
    {
        private string savePath;
        private string getUrl;
        private WebBrowser wb;
        private int iImgCount;
        //初始化參數(shù)
        public GatherPic(string sWebUrl, string sSavePath)
        {
            this.getUrl = sWebUrl;
            this.savePath = sSavePath;
        }
        //開始采集
        public bool start()
        {
            if (getUrl.Trim().Equals(""))
            {
                MessageBox.Show("哪來的蝦米連網(wǎng)址都沒輸!");
                return false;
            }
            this.wb = new WebBrowser();
            this.wb.Navigate(getUrl);
            //委托事件
            this.wb.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
            return true;
        }
        //WebBrowser.DocumentCompleted委托事件
        private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //頁面里框架iframe加載完成不掉用SearchImgList()
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 观塘区| 赫章县| 深圳市| 崇阳县| 清涧县| 屏边| 南丹县| 保德县| 柳河县| 封丘县| 江川县| 施甸县| 辽中县| 阳曲县| 宁陕县| 丽水市| 三亚市| 平罗县| 虞城县| 随州市| 丰都县| 四子王旗| 喜德县| 嘉荫县| 信宜市| 略阳县| 盐津县| 岳阳县| 灵台县| 峨边| 亚东县| 东兴市| 高淳县| SHOW| 蓝田县| 忻州市| 康乐县| 麻阳| 泸溪县| 疏勒县| 湖北省|