This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
@@ -55,6 +56,7 @@
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GDI32.cs" />
|
||||
<Compile Include="IHTMLElementRender.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
@@ -79,6 +81,27 @@
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="MSHTML">
|
||||
<Guid>{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}</Guid>
|
||||
<VersionMajor>4</VersionMajor>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>primary</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
</COMReference>
|
||||
<COMReference Include="SHDocVw">
|
||||
<Guid>{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>1</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
1
Form1.Designer.cs
generated
1
Form1.Designer.cs
generated
@@ -96,6 +96,7 @@
|
||||
this.Name = "Form1";
|
||||
this.Text = "Form1";
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
|
||||
225
Form1.cs
225
Form1.cs
@@ -7,18 +7,30 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using mshtml;
|
||||
using System.Web;
|
||||
|
||||
namespace CyworldDownloader
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
string strLoginURL = "http://www.cyworld.com";
|
||||
string strContentURL = "http://minihp.cyworld.com/pims/board/image/imgbrd_list.asp?tid=21572675&cpage=1";
|
||||
string strContentURL = "http://minihp.cyworld.com/pims/board/image/imgbrd_list.asp?tid=21572675&cpage=";
|
||||
|
||||
int m_iPage = 1;
|
||||
int m_iLastPage = 616; // 616
|
||||
|
||||
bool m_bFirst = true;
|
||||
|
||||
string ORGCONTENTS_PATH = Application.StartupPath + "\\Originals";
|
||||
string CONTENTS_PATH = Application.StartupPath + "\\Contents";
|
||||
string IMAGE_PATH = Application.StartupPath + "\\Contents\\Images";
|
||||
|
||||
List<string> photoURLlist = new List<string>();
|
||||
|
||||
StreamWriter m_ImgLog = null;
|
||||
StreamWriter m_ImgLog2 = null;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -26,9 +38,39 @@ namespace CyworldDownloader
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
DirectoryInfo di = new DirectoryInfo(ORGCONTENTS_PATH);
|
||||
if(di.Exists == false)
|
||||
di.Create();
|
||||
|
||||
di = new DirectoryInfo(CONTENTS_PATH);
|
||||
if(di.Exists == false)
|
||||
di.Create();
|
||||
|
||||
di = new DirectoryInfo(IMAGE_PATH);
|
||||
if(di.Exists == false)
|
||||
di.Create();
|
||||
|
||||
m_ImgLog = new StreamWriter(CONTENTS_PATH + "\\ImageLinks.html", true);
|
||||
m_ImgLog2 = new StreamWriter(CONTENTS_PATH + "\\ImageLinks2.html", true, Encoding.UTF8);
|
||||
|
||||
wbLogin.Navigate(strLoginURL);
|
||||
}
|
||||
|
||||
private void btDebug_Click(object sender, EventArgs e)
|
||||
{
|
||||
string org = "IMG%5F2421+%BA%B9%BB%E7%2Ejpg";
|
||||
string str2 = HttpUtility.UrlDecode(org, Encoding.Default);
|
||||
string str3 = HttpUtility.UrlEncode(str2);
|
||||
|
||||
Console.WriteLine("break");
|
||||
}
|
||||
|
||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
m_ImgLog.Close();
|
||||
m_ImgLog2.Close();
|
||||
}
|
||||
|
||||
private void wbLogin_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
|
||||
{
|
||||
WebBrowser browser = (WebBrowser)sender;
|
||||
@@ -48,7 +90,7 @@ namespace CyworldDownloader
|
||||
else
|
||||
{
|
||||
photoURLlist.Clear();
|
||||
wbContent.Navigate(strContentURL);
|
||||
wbContent.Navigate(strContentURL+m_iPage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,13 +100,21 @@ namespace CyworldDownloader
|
||||
if(e.Url.Host != browser.Url.Host)
|
||||
return;
|
||||
|
||||
HtmlElement element = browser.Document.GetElementsByTagName("BODY")[0];
|
||||
HtmlElement element = browser.Document.GetElementsByTagName("HTML")[0];
|
||||
string strHTML = element.OuterHtml;
|
||||
|
||||
//StreamWriter writer = new StreamWriter("content.html");
|
||||
//writer.Write(element.InnerHtml);
|
||||
//writer.Close();
|
||||
strHTML = strHTML.Replace("<BODY oncontextmenu=\"return false\"", "<BODY");
|
||||
|
||||
string strTarget = element.InnerHtml;
|
||||
string strFileName = string.Format("{0}\\Content{1:000}.html", ORGCONTENTS_PATH, m_iPage);
|
||||
StreamWriter writer = new StreamWriter(strFileName, false, Encoding.UTF8);
|
||||
writer.Write(strHTML);
|
||||
writer.Close();
|
||||
|
||||
string strLine = string.Format("<br><strong>Page {0}</strong><br>", m_iPage);
|
||||
m_ImgLog.WriteLine(strLine);
|
||||
m_ImgLog2.WriteLine(strLine);
|
||||
|
||||
string strTarget = strHTML;
|
||||
while(true)
|
||||
{
|
||||
int iPos = strTarget.IndexOf("file_down");
|
||||
@@ -72,20 +122,58 @@ namespace CyworldDownloader
|
||||
break;
|
||||
|
||||
int iPos2 = strTarget.Substring(Math.Max(iPos-200, 0), 200).LastIndexOf("http") + Math.Max(iPos-200, 0);
|
||||
int iPos3 = strTarget.Substring(iPos2, 500).IndexOf("\"") + iPos2;
|
||||
|
||||
int iPos3_1 = strTarget.Substring(iPos2, 500).IndexOf("\"");
|
||||
int iPos3_2 = strTarget.Substring(iPos2, 500).IndexOf("'");
|
||||
int iPos3 = 0;
|
||||
if(iPos3_1 < 0 || iPos3_2 < 0)
|
||||
iPos3 = Math.Max(iPos3_1, iPos3_2);
|
||||
else
|
||||
iPos3 = Math.Min(iPos3_1, iPos3_2);
|
||||
if(iPos3 < 0)
|
||||
{
|
||||
strTarget.Remove(iPos, "file_down".Length);
|
||||
Console.WriteLine("Page {0} cannot find Pos3");
|
||||
continue;
|
||||
}
|
||||
iPos3 += iPos2;
|
||||
|
||||
string photourl = strTarget.Substring(iPos2, iPos3-iPos2);
|
||||
|
||||
string newPhotoURL = photourl;
|
||||
newPhotoURL = HttpUtility.UrlDecode(newPhotoURL, Encoding.Default);
|
||||
|
||||
|
||||
strLine = string.Format("<a href='{0}'>{0}</a><br>", photourl);
|
||||
m_ImgLog.WriteLine(strLine);
|
||||
strLine = string.Format("<a href='{0}'>{0}</a><br>", newPhotoURL);
|
||||
m_ImgLog2.WriteLine(strLine);
|
||||
|
||||
|
||||
string[] tokens = newPhotoURL.Split('/');
|
||||
newPhotoURL = tokens.Last();
|
||||
strTarget = strTarget.Replace(photourl, "Images/"+newPhotoURL);
|
||||
|
||||
|
||||
photoURLlist.Add(photourl);
|
||||
Console.WriteLine(photourl);
|
||||
|
||||
strTarget = strTarget.Substring(iPos3, strTarget.Length-iPos3);
|
||||
}
|
||||
m_ImgLog.Flush();
|
||||
m_ImgLog2.Flush();
|
||||
|
||||
if(photoURLlist.Count > 0)
|
||||
wbPhoto.Navigate(photoURLlist[0]);
|
||||
strFileName = string.Format("{0}\\Content{1:000}.html", CONTENTS_PATH, m_iPage);
|
||||
writer = new StreamWriter(strFileName, false, Encoding.UTF8);
|
||||
writer.Write(strTarget);
|
||||
writer.Close();
|
||||
|
||||
|
||||
if(m_iPage < m_iLastPage)
|
||||
{
|
||||
m_iPage++;
|
||||
wbContent.Navigate(strContentURL+m_iPage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void wbPhoto_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
|
||||
{
|
||||
WebBrowser browser = (WebBrowser)sender;
|
||||
@@ -96,48 +184,85 @@ namespace CyworldDownloader
|
||||
// 참고
|
||||
// http://www.developerfusion.com/code/4712/generate-an-image-of-a-web-page/
|
||||
|
||||
using (Graphics srcGraphics = browser.CreateGraphics())
|
||||
{
|
||||
using (Graphics destGraphics = this.pictureBox1.CreateGraphics())
|
||||
{
|
||||
IntPtr hdcDest = destGraphics.GetHdc();
|
||||
IntPtr hdcSrc = srcGraphics.GetHdc();
|
||||
GDI32.BitBlt(
|
||||
hdcDest,
|
||||
0, 0,
|
||||
browser.ClientRectangle.Width, browser.ClientRectangle.Height,
|
||||
hdcSrc,
|
||||
0, 0,
|
||||
(int) GDI32.SRCCOPY
|
||||
);
|
||||
srcGraphics.ReleaseHdc(hdcSrc);
|
||||
destGraphics.ReleaseHdc(hdcDest);
|
||||
}
|
||||
}
|
||||
|
||||
//HtmlDocument dom = browser.Document;
|
||||
|
||||
//htmlc
|
||||
|
||||
//IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
|
||||
//IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
|
||||
|
||||
//foreach(IHTMLImgElement img in doc.images)
|
||||
//using (Graphics srcGraphics = browser.CreateGraphics())
|
||||
//{
|
||||
// imgRange.add((IHTMLControlElement)img);
|
||||
// using (Graphics destGraphics = this.pictureBox1.CreateGraphics())
|
||||
// {
|
||||
// IntPtr hdcDest = destGraphics.GetHdc();
|
||||
// IntPtr hdcSrc = srcGraphics.GetHdc();
|
||||
// GDI32.BitBlt(
|
||||
// hdcDest,
|
||||
// 0, 0,
|
||||
// browser.ClientRectangle.Width, browser.ClientRectangle.Height,
|
||||
// hdcSrc,
|
||||
// 0, 0,
|
||||
// (int) GDI32.SRCCOPY
|
||||
// );
|
||||
// srcGraphics.ReleaseHdc(hdcSrc);
|
||||
// destGraphics.ReleaseHdc(hdcDest);
|
||||
// }
|
||||
//}
|
||||
|
||||
// imgRange.execCommand("Copy", false, null);
|
||||
|
||||
// using(Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
|
||||
//IHTMLDocument2 document = (mshtml.IHTMLDocument2)browser.Document.DomDocument;
|
||||
//if(document != null)
|
||||
//{
|
||||
// IHTMLElement element = (IHTMLElement)document.body;
|
||||
// if(element != null)
|
||||
// {
|
||||
// bmp.Save(@"C:\"+img.nameProp);
|
||||
// IHTMLElementRender render = (IHTMLElementRender)element;
|
||||
// if(render != null)
|
||||
// {
|
||||
// using(Graphics graphics = this.pictureBox1.CreateGraphics())
|
||||
// {
|
||||
// IntPtr hdc = graphics.GetHdc();
|
||||
// render.DrawToDC(hdc);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
private void btDebug_Click(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine("break");
|
||||
IHTMLDocument2 document = (IHTMLDocument2)browser.Document.DomDocument;
|
||||
if(document != null)
|
||||
{
|
||||
IHTMLElement element = (IHTMLElement)document.body;
|
||||
if(element != null)
|
||||
{
|
||||
IHTMLElementRender render = (IHTMLElementRender)element;
|
||||
if(render != null)
|
||||
{
|
||||
using(Graphics graphics = this.pictureBox1.CreateGraphics())
|
||||
{
|
||||
IntPtr hdcDestination = graphics.GetHdc();
|
||||
render.DrawToDC(hdcDestination);
|
||||
IntPtr hdcMemory = GDI32.CreateCompatibleDC(hdcDestination);
|
||||
IntPtr bitmap = GDI32.CreateCompatibleBitmap(
|
||||
hdcDestination,
|
||||
browser.ClientRectangle.Width, browser.ClientRectangle.Height
|
||||
);
|
||||
|
||||
if(bitmap != IntPtr.Zero)
|
||||
{
|
||||
IntPtr hOld = (IntPtr)GDI32.SelectObject(hdcMemory, bitmap);
|
||||
GDI32.BitBlt(
|
||||
hdcMemory,
|
||||
0, 0,
|
||||
browser.ClientRectangle.Width, browser.ClientRectangle.Height,
|
||||
hdcDestination,
|
||||
0, 0,
|
||||
(int)GDI32.TernaryRasterOperations.SRCCOPY
|
||||
);
|
||||
GDI32.SelectObject(hdcMemory, hOld);
|
||||
GDI32.DeleteDC(hdcMemory);
|
||||
graphics.ReleaseHdc(hdcDestination);
|
||||
|
||||
pictureBox1.Image = Image.FromHbitmap(bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pictureBox1.Image.Save("image.bmp");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
GDI32.cs
12
GDI32.cs
@@ -2,12 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace CyworldDownloader
|
||||
{
|
||||
class GDI32
|
||||
{
|
||||
public const int SRCCOPY = 0xCC0020;
|
||||
public enum TernaryRasterOperations
|
||||
{
|
||||
SRCCOPY = 0xCC0020
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
|
||||
public static extern int BitBlt(
|
||||
@@ -30,5 +34,11 @@ namespace CyworldDownloader
|
||||
|
||||
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
|
||||
public static extern void DeleteObject(IntPtr obj);
|
||||
|
||||
[DllImport("gdi32.dll", EntryPoint="DeleteDC")]
|
||||
public static extern bool DeleteDC([In] IntPtr hdc);
|
||||
|
||||
[DllImport("gdi32.dll", EntryPoint="CreateCompatibleBitmap")]
|
||||
public static extern IntPtr CreateCompatibleBitmap([In] IntPtr hdc, int nWidth, int nHeight);
|
||||
}
|
||||
}
|
||||
|
||||
56
IHTMLElementRender.cs
Normal file
56
IHTMLElementRender.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using SHDocVw;
|
||||
using mshtml;
|
||||
|
||||
namespace CyworldDownloader
|
||||
{
|
||||
[
|
||||
Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"),
|
||||
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
|
||||
ComVisible(true),
|
||||
ComImport
|
||||
]
|
||||
interface IHTMLElementRender
|
||||
{
|
||||
void DrawToDC([In] IntPtr hDC);
|
||||
void SetDocumentPrinter([In, MarshalAs(UnmanagedType.BStr)] string bstrPrinterName, [In] IntPtr hDC);
|
||||
};
|
||||
|
||||
public class IEElementCapture
|
||||
{
|
||||
private IWebBrowser2 webBrowser = null;
|
||||
|
||||
public IEElementCapture(IWebBrowser2 webBrowser)
|
||||
{
|
||||
this.webBrowser = webBrowser;
|
||||
}
|
||||
|
||||
public bool Capture(ref Graphics g)
|
||||
{
|
||||
if(null == webBrowser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IHTMLDocument2 htmlDocument = (IHTMLDocument2)webBrowser.Document;
|
||||
if(null != htmlDocument)
|
||||
{
|
||||
IHTMLElement bodyElement = (IHTMLElement)htmlDocument.body;
|
||||
if(null != bodyElement)
|
||||
{
|
||||
IHTMLElementRender render = (IHTMLElementRender)bodyElement;
|
||||
if(null != render)
|
||||
{
|
||||
IntPtr memDC = g.GetHdc();
|
||||
render.DrawToDC(memDC);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user