【问题标题】:google image search api in .NET.NET 中的谷歌图片搜索 API
【发布时间】:2011-07-03 12:44:24
【问题描述】:

我有一个用于谷歌图片搜索的 api,但那个太旧了,在目前的谷歌图片搜索中不起作用,那么有没有最新的谷歌图片搜索 api?

【问题讨论】:

标签: c# .net google-api


【解决方案1】:

【讨论】:

    【解决方案2】:
    string imgurl = "https://fun.vin/frank-capra-jr";
    
            var documents = new HtmlWeb().Load(imgurl);
            var urls = (documents.DocumentNode.Descendants("img")
                                            .Select(e => e.GetAttributeValue("src", null))
                                            .Where(s => !String.IsNullOrEmpty(s))).ToList();
            int c = 0;
             foreach(string a in urls)
            {
                string url = a;
    
                using (WebClient webClient = new WebClient())
                {
                    string imageUrl = url;
                    //string saveLocation = @"C:\New folder (2)\car\someImage.jpg";
    
                    byte[] imageBytes;
                    HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl);
                    WebResponse imageResponse = imageRequest.GetResponse();
    
                    Stream responseStream = imageResponse.GetResponseStream();
    
                    using (BinaryReader br = new BinaryReader(responseStream))
                    {
                        imageBytes = br.ReadBytes(500000);
                        br.Close();
                    }
                    responseStream.Close();
                    imageResponse.Close();
    
                    int Hight = 0;
                    int wedht = 0;
                    Image image = null;
                    using (MemoryStream stream = new MemoryStream(imageBytes))
                    {
                         image = Image.FromStream(stream);
    
                    }
                    ImageFormat ab = image.RawFormat;
    
                    string ext = new ImageFormatConverter().ConvertToString(ab);
    
                    //if (ImageFormat.Jpeg.Equals(image.RawFormat))
                    //{
                    //    // JPEG
                    //}
                    //else if (ImageFormat.Png.Equals(image.RawFormat))
                    //{
                    //    // PNG
                    //}
                    //else if (ImageFormat.Gif.Equals(image.RawFormat))
                    //{
                    //    // GIF
                    //}
                    Hight = image.Height;
                    wedht = image.Width;
                    if (!ImageFormat.Gif.Equals(image.RawFormat))
                    {
                        string saveLocation = @"C:\New folder (2)\car\someImage" + c + "." + ext;// + "jpg";
    
                        FileStream fs = new FileStream(saveLocation, FileMode.Create);
                        BinaryWriter bw = new BinaryWriter(fs);
                        try
                        {
                            bw.Write(imageBytes);
                            c++;
                        }
                        finally
                        {
                            fs.Close();
                            bw.Close();
                        }
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-18
      相关资源
      最近更新 更多