private
void
button1_Click(
object
sender, EventArgs e)
{
Thread thread =
new
Thread(Download);
thread.Start();
}
public
void
Download()
{
for
(
int
i = 1; i <= 22; i++)
{
string
url =
"https://www.xiurenji.com/XiuRen/6545"
;
url +=
"_"
+ i +
".html"
;
string
code = GetWebClient(url);
MatchCollection mc = Regex.Matches(code,
@"uploadfile/202009/23/[0-9A-Za-z]{10}.jpg"
);
foreach
(Match mat
in
mc)
{
string
url1 =
"https://img1.xiurenji.com/"
;
url1 += mat.ToString();
ImgSave(url1);
}
}
}
/// 图片另存为
/// </summary>
/// <param name="url">路径</param>
public
void
ImgSave(
string
url)
{
WebRequest imgRequest = WebRequest.Create(url);
HttpWebResponse res;
try
{
res = (HttpWebResponse)imgRequest.GetResponse();
}
catch
(WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
if
(res.StatusCode.ToString() ==
"OK"
)
{
System.Drawing.Image downImage = System.Drawing.Image.FromStream(imgRequest.GetResponse().GetResponseStream());
string
deerory =
string
.Format(
@"D:\img\{0}\"
, DateTime.Now.ToString("yyyy-MM-dd"));
string
fileName =
string
.Format(
"{0}.png"
, DateTime.Now.ToString(
"HHmmssffff"
));
if
(!System.IO.Directory.Exists(deerory))
{
System.IO.Directory.CreateDirectory(deerory);
}
downImage.Save(deerory + fileName);
downImage.Dispose();
}
}