[ÄÚµù?] ¸Þ¸ðÀå¿¡ ÀÔ·ÂµÈ Æ¯Á¤ ÁÖ¼ÒµéÀÇ ÆÄÀÏÀ» ¼ø¼´ë·Î ¹Þ´Â¹æ¹ý?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Threading;
namespace Downloader
{
class Program
{
static void Main(string[] args)
{
string[] lines = File.ReadAllLines("E:/ backup/list.txt");
foreach (string entry in lines)
{
string savePath = $"E:/backup/{entry.Replace("/", "_")}/";
try
{
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
Console.WriteLine("[작업시작] 대상주소: {0}", entry);
for(int i = 0;i < 1000;i++)
//Parallel.For(0, 1001, new ParallelOptions() { MaxDegreeOfParallelism = 10 }, (i) =>
{
try
{
string fullUrl = $"{entry}{i:0000}.txt";
string fileName = $"{i:0000}.txt";
using (WebClient wc = new WebClient())
{
wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36");
wc.DownloadFile(fullUrl, Path.Combine(savePath, fileName));
}
}
catch (Exception ex)
{
Console.WriteLine("[오류] {0}", ex.Message);
i--;
Thread.Sleep(3000);
}
}//);
}
catch (Exception ex)
{
Console.WriteLine("[오류] {0}", ex.Message);
}
}
Console.WriteLine("작업 완료");
}
}
}
c# 코드입니다
텍스트문서에
a.com/1/
a.com/2/
a.com/3/
b.com/1/
b.com/2/
b.com/3/
이렇게 있다면 a.com_1 폴더 생성후 하위에 0000.txt ~ 1000.txt 로 다운받습니다
Parallel 으로 멀티스레딩 동시에 10개 다운로드하구요, MaxDegreeOfParallelism 를 조절하시면 동시에 병렬작업하실 스레드 갯수를 지정하시면됩니다
하시려는 작업을 상세히 알려주시면 c# 으로 컴파일해서 만들어 드릴수도 있습니다~
Çѹø ½ÇÇàÇغ¸°Ú½À´Ï´Ù °¨»çÇÕ´Ï´Ù
1. º´·Ä·Î ½ÇÇàÇغ¸´Ï±î °ø°ÝÀ¸·Î ÀνÄÇÏ°í Â÷´ÜÇعö¸®³×¿ä. ÀÌ°Ç Â÷Ä¡ÇÏ°í..
2. µµÁß¿¡ µð½ºÄ¿³Ø¼ÇÀÌ µÇ¾úÀ»¶§ ÇÁ·Î±×·¥ÀÌ ²¨Áö´Â°Å.. ÇÑ 10ÃÊ~20ÃÊÀÖ´Ù Áß´ÜµÈ ºÎºÐºÎÅÍ Àç½ÃÀ۵Ǹé ÁÁ°Ú´Âµ¥..
ÀÌÁ¤µµ°¡ ¹®Á¦³×¿ä. ÇÏ·Á´Â ÀÛ¾÷Àº »ç½Ç ÅؽºÆ®°¡ ¾Æ´Ï¶ó .ts ½ºÆ®¸®¹ÖÆÄÀÏ Á¶°¢À» ±Ü¾îº¸´Â °Çµ¥, ¸¶À½Ã³·³ ½±Áø¾Ê³×¿ä
ÁÖ¼Ò´Â Çü½ÄÀº https://ÁÖ¼Ò/ÁÖ¼Ò/0000.ts ~ https://ÁÖ¼Ò/ÁÖ¼Ò/1000.ts ±îÁöÀÔ´Ï´Ù.
º´·ÄºÎºÐÀº Á¦¿ÜÇÏ°í¼¶óµµ ÁߴܵǸé ÇØ´ç ºÎºÐ ºÎÅÍ ½Ã°£À» ÁØ ÈÄ ´Ù½Ã½ÃÀÛ. ÀÌ·±°Å¸¸ °¡´ÉÇÏ°í.. ÄÄÆÄÀÏÀÌ µÇ½Ã´ÂÁö¿ä??
Á¦ ½Ã½ºÅÛ¿¡¼± ÀÌ»óÇÏ°Ô ÄÄÆÄÀÏÀÌ ¾ÈµÇ³×¿ä ..
10³âÀÌ ³Ñ¾úÁö¸¸ ÄÚµå ¾µÁÙÀº ¸ô¶óµµ ÀÐÀ»ÁÙÀº ¾Ë¾Æ¼ Å« Ʋ¸¸ À־ ±¦ÂúÀ» °Í °°½À´Ï´Ù.
÷ºÎÆÄÀÏ¿¡ ºñÁê¾ó½ºÆ©µð¿À ¼Ö·ç¼ÇÆÄÀÏ Ã·ºÎÇß½À´Ï´Ù. ºôµåÆú´õº¸½Ã¸é ÄÄÆÄÀÏµÈ exeÆÄÀϵµ Æ÷ÇԵǾîÀÕÀ»°Å±¸¿ä
Ȥ½Ã¸ô¶óµµ User-Agnet´Â Å©·Ò°ú °°Àº°ÍÀ¸·Î ÁöÁ¤Çصξú½À´Ï´Ù
string[] lines = File.ReadAllLines("E:/ backup/list.txt");
foreach (string entry in lines)
{
string savePath = $"E:/backup/{entry.Replace("/", "_")}/";
ÀÌ ºÎºÐ ¹®Á¦¿´³×¿ä.
°¢ ÁÙÀ» entry·Î ¹Þ´Â°úÁ¤¿¡¼, ÁÖ¼Ò°¡ entry·Î ¹Þ°ÔµÇ¾îÀÖ¾î ÀϺΠ¹®ÀÚ°¡ Æú´õ¸íÀ¸·Î ÁöÁ¤µÇÁö ¸øÇÏ´Â °Í °°Àºµ¥,
¾Æ¿¹ ù¹ø° ÁÙÀº 1¹øÆú´õ.. µÎ¹ø° ÁÙÀº 2Æú´õ
ÀÌ·±½ÄÀ¸·Î Æú´õÀ̸§À» ¹è¿¼ø¼·Î ¹Ù²Ü¼ö ÀÖÀ»±î¿ä?
linenum++;
string savePath = $"E:/backup/{linenum}/";
Ãß°¡Çؼ ÇØ°áÇß½À´Ï´Ù..
Äڵ带 ÀÐÀ» ¼ø Àְڴµ¥ C#Àº ¾î±ú³Ñ¾î¹è¿îµ¥´Ù°¡.. ´Ù½Ã ¼öÁ¤ÇÏ·Á´Ï ¹®Á¦°¡ »ý±é´Ï´Ù.
catch (Exception ex)
ÀÌ ºÎºÐÀ» Á¶±Ý ¼öÁ¤ÇßÀ¸¸é ÁÁ°Ú´Âµ¥. ±âÁ¸ Ä¿³Ø¼ÇÀ» °ø°ÝÀ¸·Î °£ÁÖÇÒ°æ¿ì ½½¸®ÇÁ¸¦ À¯ÁöÈÄ Àç½Ãµµ´Â À¯ÁöÇϸé¼.
0000.ts¸¦ ´Ù¿î·Îµå ½ÃÀÛÇؼ,
0100.ts±îÁö Á¤»óÀûÀ¸·Î ´Ù¿î·Îµå ÇÑ ÀÌÈÄ
0101.ts ÆÄÀÏÀÌ ¾ø¾î¼ 404¸¦ ¹Ýȯ½Ã
404¿¡·¯ ÀνÄÀÌÈÄ´Â ¹Ýº¹À» Å»ÃâÇؼ ´ÙÀ½ ÁÙ
0000.ts ºÎÅÍ ´Ù¿î·Îµå ½ÃÀÛ
ÀÌ·¯´Â°Ô °¡´ÉÇÒÁö¿ä? ÀÏ´Ü sleepÀº Àß ÀÛµ¿ÇÏ´Â µí ÇÕ´Ï´Ù..
ÇØ´ç Http ÇÁ·ÎÅäÄÝÀÇ ¿À·ù Response°¡ 404 (ÆäÀÌÁö¾øÀ½)ÀÇ °æ¿ì ÇØ´ç ¹Ýº¹¹®À» Break;ÇÏ°Ô Ã³¸®ÇØÁÖ¸éµÉµíÇÕ´Ï´Ù
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse response = ex.Response as HttpWebResponse;
if (response != null)
{
if ((int)response.StatusCode == 404) // Not Found
{
break;
}
}
}
}
exceptionºÎºÐ¿¡ i--¸¦ »«´ÙÀ½¿¡ i++·Î ¹Ù²ã¼ °è¼ÓÁøÇàÇÏ°ÔÇÏ°í ·Î±×¸¦µû·Î»Ì¾Æ¼ Àç½ÃµµÇÏ°Ô²û®³×¿ä.
(int)response.StatusCode ·Î Çß´õ´Ï °è¼Ó ¿¡·¯°¡¶°¼..
»õÇØ º¹ ¸¹À̹ÞÀ¸½Ã°í ´Ù½ÃÇѹø °¨»çÇÕ´Ï´Ù. ÀÛ¾÷ ´Ù ³¡³Â³×¿ä ¤¾¤¾