using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tool;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
namespace Search
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/**
* ???У????潫??????URL
*/
public class Queue
{
//?????????????
private LinkedList<string> queue = new LinkedList<string>();
//?????
public void enQueue(string t)
{
queue.AddLast(t);
}
//??????
public string deQueue()
{
string o = queue.Last.Value;
queue.RemoveLast();
return o;
}
//?ж??????????
public bool isQueueEmpty()
{
return queue.Count > 0 ? false : true;
}
//?ж??????????t
public bool contians(string t)
{
return queue.Contains(t);
}
public int getcount()
{
return queue.Count;
}
}
public class LinkQueue
{
//??????url ????
private static ISet<string> visitedUrl = new HashSet<string>();
//???????url ????
private static Queue unVisitedUrl = new Queue();
//???URL ????
public static Queue getUnVisitedUrl()
{
return unVisitedUrl;
}
//???????????URL ??????
public static void addVisitedUrl(String url)
{
visitedUrl.Add(url);
}
//??????????URL
public static void removeVisitedUrl(String url)
{
visitedUrl.Remove(url);
}
//δ?????URL ??????
public static Object unVisitedUrlDeQueue()
{
return unVisitedUrl.deQueue();
}
// ??????URL ??????????
public static void addUnvisitedUrl(String url)
{
if (url != null && !url.Trim().Equals("")
&& !visitedUrl.Contains(url)
&& !unVisitedUrl.contians(url))
unVisitedUrl.enQueue(url);
}
//???????????URL ???
public static int getVisitedUrlNum()
{
return visitedUrl.Count;
}
//?ж?δ?????URL ????????????
public static bool unVisitedUrlsEmpty()
{
return unVisitedUrl.isQueueEmpty();
}
}
string[] urlarr=new string[100];
private void button1_Click(object sender?? EventArgs e)
{
zzHttp http = new zzHttp();
CookieContainer cookie = new CookieContainer();
string url = textBox1.Text!=""?textBox1.Text:"http://image.baidu.com/";
string content=http.SendDataByGET(url??""??ref cookie);
string baseUri = Utility.GetBaseUri(url);
string[] links = Parser.ExtractLinks(baseUri?? content);
foreach (string link in links)
{
richTextBox1.Text += link;
richTextBox1.Text += " ";
}
Regex regImg = new Regex(@"<img[^<>]*?src[s ]*=[s ]*[""']?[s ]*(?<imgUrl>[^s ""'<>]*)[^<>]*?/?[s ]*>"?? RegexOptions.IgnoreCase);            // ?????????????
MatchCollection matches = regImg.Matches(content);
Queue que = new Queue();
foreach (Match match in matches)
que.enQueue(match.Groups["imgUrl"].Value);
int k;
for (k = 0; k < que.getcount(); k++)
{
string picurl = que.deQueue();
richTextBox1.Text += picurl;
richTextBox1.Text += " ";
string[] s = picurl.Split('/');
string picname=s[s.Length - 1];
zzHttp.downfile(picurl?? picname?? @"d:pic");
}
label1.Text = k+"??";
}