zoukankan      html  css  js  c++  java
  • 下载百度上的图片C#——输入名字就可以下载

    using System;

    using System.Collections.Generic;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Net;

    using System.Text;

    using System.IO;

    using System.Text.RegularExpressions;

    namespace crawel_picture {    

    class Program     {                

    static void Main(string[] args)       

      {            

        IList<string> path = new List<string>();               

      string strHTML = "";               

      string name = "水杯";                

    int num1 = 2;                

    int num = 2000000;               

    WebClient myWebClient = new WebClient();               

    Stream myStream = myWebClient.OpenRead("http://image.baidu.com/i?tn=baiduimage&ct=201326592&lm=-1&cl=2&nc=1&word=" + name + "&ie=utf-8&ie=utf-8");                StreamReader sr = new StreamReader(myStream, System.Text.Encoding.GetEncoding("utf-8"));               

    strHTML = sr.ReadToEnd();             

      myStream.Close();              

      MatchCollection lrc1 = Regex.Matches(strHTML, @"[objURL]{6}.:.http://.*");                

      foreach (Match s in lrc1)              

        {               

            path.Add(Regex.Split(s.ToString(), """)[2].ToString());                        

            }                

      for (int i = 0; i < path.Count;i++ )                

      {                 

         num++;                     

         myWebClient.DownloadFile(path[i], @"E:爬虫图片" + num1 + "\" + num.ToString() + ".jpg");            

      }   

          }     

           }    

    }

  • 相关阅读:
    【转】QT中添加的资源文件qrc时的路径问题小结
    【转】Qt 资源图片删除后,错误 needed by `debug/qrc_image.cpp'. Stop. 的终极解决办法
    普通类型与自定义类型之间的转化
    快速实现python c扩展模块
    关于解决python线上问题的几种有效技术
    OpenGL超级宝典笔记----渲染管线
    读python源码--对象模型
    python与c互相调用
    OpenGL超级宝典笔记----框架搭建
    python笔记(持续更新)
  • 原文地址:https://www.cnblogs.com/Lxiaojiang/p/5337356.html
Copyright © 2011-2022 走看看