2014년 9월 24일 수요일
2014년 8월 17일 일요일
load dll asm
.file "loaddllex.cpp"
.intel_syntax noprefix
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "C:\\work\\dummy.dll\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
LFB6:
lea ecx, [esp+4]
LCFI0:
and esp, -16
push DWORD PTR [ecx-4]
push ebp
LCFI1:
mov ebp, esp
push ecx
LCFI2:
sub esp, 36
call ___main
mov DWORD PTR [esp], OFFSET FLAT:LC0
call _LoadLibraryA@4
sub esp, 4
mov DWORD PTR [ebp-12], eax
mov eax, 0
mov ecx, DWORD PTR [ebp-4]
LCFI3:
leave
LCFI4:
lea esp, [ecx-4]
LCFI5:
ret
LFE6:
.section .eh_frame,"w"
Lframe1:
.long LECIE1-LSCIE1
LSCIE1:
.long 0
.byte 0x3
.ascii "\0"
.uleb128 0x1
.sleb128 -4
.uleb128 0x8
.byte 0xc
.uleb128 0x4
.uleb128 0x4
.byte 0x88
.uleb128 0x1
.align 4
LECIE1:
LSFDE1:
.long LEFDE1-LASFDE1
LASFDE1:
.long LASFDE1-Lframe1
.long LFB6
.long LFE6-LFB6
.byte 0x4
.long LCFI0-LFB6
.byte 0xc
.uleb128 0x1
.uleb128 0
.byte 0x4
.long LCFI1-LCFI0
.byte 0x10
.byte 0x5
.uleb128 0x2
.byte 0x75
.sleb128 0
.byte 0x4
.long LCFI2-LCFI1
.byte 0xf
.uleb128 0x3
.byte 0x75
.sleb128 -4
.byte 0x6
.byte 0x4
.long LCFI3-LCFI2
.byte 0xc
.uleb128 0x1
.uleb128 0
.byte 0x4
.long LCFI4-LCFI3
.byte 0xc5
.byte 0x4
.long LCFI5-LCFI4
.byte 0xc
.uleb128 0x4
.uleb128 0x4
.align 4
LEFDE1:
.ident "GCC: (GNU) 4.8.1"
.def _LoadLibraryA@4; .scl 2; .type 32; .endef
2014년 8월 16일 토요일
k-mean clustering
require(graphics)
beta1<-c(-0.130811881,-0.124113184,-0.111084035,-0.346505179,0.146765992,-0.203682819)
beta2<-c(0.19744896,0.158675025,0.098311959,0.644843941,-0.197478252,0.278922585)
beta1<-c(-0.130811881, -0.124113184, -0.111084035, -0.346505179, 0.146765992, -0.201818799, 0.109229194, -0.203682819, -0.124113184, -0.065281704, -0.089614531)
beta2<-c(0.19744896, 0.158675025, 0.098311959, 0.644843941, -0.197478252, 0.100779252, -0.204082744, 0.278922585, 0.158675025, 0.099221018, 0.136914875)
x <- cbind(beta1, beta2)
colnames(x) <- c("x", "y")
(cl <- kmeans(x, 2))
plot(x, col = cl$cluster)
points(cl$centers, col = 1:2, pch = 8, cex = 2)
# sum of squares
ss <- function(x) sum(scale(x, scale = FALSE)^2)
## cluster centers "fitted" to each obs.:
fitted.x <- fitted(cl); head(fitted.x)
resid.x <- x - fitted(cl)
## Equalities : ----------------------------------
cbind(cl[c("betweenss", "tot.withinss", "totss")], # the same two columns
c(ss(fitted.x), ss(resid.x), ss(x)))
stopifnot(all.equal(cl$ totss, ss(x)),
all.equal(cl$ tot.withinss, ss(resid.x)),
## these three are the same:
all.equal(cl$ betweenss, ss(fitted.x)),
all.equal(cl$ betweenss, cl$totss - cl$tot.withinss),
## and hence also
all.equal(ss(x), ss(fitted.x) + ss(resid.x))
)
kmeans(x,1)$withinss # trivial one-cluster, (its W.SS == ss(x))
## random starts do help here with too many clusters
## (and are often recommended anyway!):
(cl <- kmeans(x, 5, nstart = 25))
plot(x, col = cl$cluster)
points(cl$centers, col = 1:5, pch = 8)


2014년 7월 28일 월요일
prevent mouse cursor move when double click on web page
$('*').dblclick(function(event) { event.preventDefault(); return false; });
2014년 7월 27일 일요일
텍스트 파일 병합 펄 스크립트
$name = "name.txt";
$formular = "formular.txt";
$A = "A.txt";
$B = "B.txt";
$C = "C.txt";
open $fh_name, '<', $name or die "Cannot open $name: $!";
open $fh_formular, '<', $formular or die "Cannot open $formular: $!";
open $fh_A, '<', $A or die "Cannot open $A: $!";
open $fh_B, '<', $B or die "Cannot open $B: $!";
open $fh_C, '<', $C or die "Cannot open $C: $!";
open $table, '>table.txt';
my $n = @{[<$fh_name>]};
seek $fh_name,0,0;
for ($i=1; $i<= $n; $i++){
$l_name = <$fh_name>;
chomp($l_name);
$l_formular = <$fh_formular>;
chomp($l_formular);
$l_A = <$fh_A>;
chomp($l_A);
$l_B = <$fh_B>;
chomp($l_B);
$l_C = <$fh_C>;
chomp($l_C);
print $table "$l_name\t$l_formular\t$l_A\t$l_B\t$l_C\n";
}
2014년 7월 23일 수요일
이클립스 프로젝트 SWT 예제
1.[File]-[New]-[Java Project]
[New]-[Class]
2. [Project]-[Java Build Path]-[Libraries]-[Add External JARs]
[New]-[Class]
소스코드 입력
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* @author Steven Holzner
*
*/
public class SWTButtonExampleDemo {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(300, 200);
shell.setText("Button Example");
shell.setLayout(new RowLayout());
final Button button = new Button(shell, SWT.PUSH);
button.setText("Click Me");
final Text text = new Text(shell, SWT.SHADOW_IN);
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
text.setText("No worries!");
}
public void widgetDefaultSelected(SelectionEvent event) {
text.setText("No worries!");
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
2. [Project]-[Java Build Path]-[Libraries]-[Add External JARs]
2014년 7월 8일 화요일
[c#] 엑셀 파일 읽기
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 Excel = Microsoft.Office.Interop.Excel;
namespace ReadExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\\C.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
MessageBox.Show(xlRange.Cells[i, j].Value2.ToString());
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace ReadExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\\C.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
MessageBox.Show(xlRange.Cells[i, j].Value2.ToString());
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
클릭하면 div를 보여주는 jquery 소스
<button>Toggle</button>
<div id="select" style="display: none">
<p>Such interesting text, eh?</p>
</div>
<div>this is second para</div>
</body>
<script>
$( "button" ).click(function() {
$('#select').toggle( "slow" );
});
</script>
<div id="select" style="display: none">
<p>Such interesting text, eh?</p>
</div>
<div>this is second para</div>
</body>
<script>
$( "button" ).click(function() {
$('#select').toggle( "slow" );
});
</script>
2014년 6월 28일 토요일
[c#]1분 간격으로 이벤트 실행
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 System.Timers;
namespace sendgmail
{
public partial class Form1 : Form
{
static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = 60 * 1000;
timer.Enabled = true; // Enable the timer
timer.Start();
}
// 쓰레드풀의 작업쓰레드가 지정된 시간 간격으로
// 아래 이벤트 핸들러 실행
private void timer_Tick(object sender, EventArgs e)
{
// MessageBox.Show("timer success");
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
namespace sendgmail
{
public partial class Form1 : Form
{
static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = 60 * 1000;
timer.Enabled = true; // Enable the timer
timer.Start();
}
// 쓰레드풀의 작업쓰레드가 지정된 시간 간격으로
// 아래 이벤트 핸들러 실행
private void timer_Tick(object sender, EventArgs e)
{
// MessageBox.Show("timer success");
}
}
}
2014년 6월 27일 금요일
2014년 6월 26일 목요일
윈도우환경에서 autoconf 사용
mingw32를 다운받고 installer에서 msys를 선택한 후 설치한다.
명령프롬프트에서 bash 입력
./configure 명령을 사용할 수 있다.
명령프롬프트에서 bash 입력
./configure 명령을 사용할 수 있다.
2014년 6월 25일 수요일
2014년 6월 6일 금요일
2014년 6월 5일 목요일
2014년 6월 3일 화요일
get naver kin
use LWP::UserAgent;
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$filename="naverkin-phy.txt";
if(-e $filename)
{
unlink($filename);
}
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
$mech->get("http://kin.naver.com/qna/list.nhn?m=noanswer&dirId=1114&page=1");
#$no=197187698;
$list_cont = $mech->content();
$list_cont=encode("euc-kr", $list_cont);
#print $list_cont;
@link = split(/docId=(\d{9})/, $list_cont);
for ($i=1; $i<=$#link; $i++){
if ($i%2 == 1){
push(@no, $link[$i]);
}
}
@no = sort {$a <=> $b} @no; # 1,2,3 순으로 정렬; Ascending
for ($i=1; $i<=$#no; $i++){
print $no[$i]." article is extracted...\n";
# paste from url of webbrowser manually later modify
$mech->get("http://kin.naver.com/qna/detail.nhn?d1id=11&dirId=1114&docId=$no[$i]");
$cont = $mech->content();
$cont=encode("euc-kr", $cont);
#@temp = split(/og:url/, $cont);
#@temp = split(/science&no=/, $temp[1]);
#@temp = split(/&page/, $temp[1]);
@temp = split(/tit_cont/, $cont);
@temp = split(/recom_q/, $temp[1]);
@temp = split(/img/, $temp[0]);
@temp = split(/dl/, $temp[0]);
$subject = $temp[0];
$subject =~ s/">//g;
$subject =~ s/h3>//g;
$subject =~ s/<//g;
$subject =~ s/\///g;
$subject =~ s/^\s+//g;
$subject =~ s/\s+$//g;
$subject = "subject: ".$subject;
@temp = split(/tit_cont/, $cont);
@temp = split(/recom_q/, $temp[1]);
@temp = split(/<dl>/, $temp[0]);
@temp = split(/<\/dl>/, $temp[1]);
@temp = split(/<dt>/, $temp[0]);
@temp = split(/<\/dt>/, $temp[1]);
$name = $temp[0];
$name =~ s/^\s+//g;
$name =~ s/\s+$//g;
$name = "name: ".$name;
@temp = split(/본문/, $cont);
@temp = split(/게시중단 안내/, $temp[3]);
$out = $temp[1];
$out =~ s/!<--$//;
$out =~ s/<\/div>//;
$out =~ s/\!<--//;
$memo = $out;
#print $memo;
$memo = "memo: ".$memo;
@temp = split(/본문/, $cont);
@temp = split(/게시중단 안내/, $temp[3]);
@img_url = split(/src="/,$temp[1]);
@img_url = split(/\?type/,$img_url[1]);
#print $img_url[0];
$img_url[0]=~ m/jpg|png|JPG|PNG/;
if ($img_url[0]){
$img_type = $&;
$mech->mirror($img_url[0], $no.".".$img_type);
}
$attached = "file:".$no.".".$img_type;
open MYFILE, ">>", "naverkin-phy.txt" or die ;
print MYFILE "$no[$i]";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
print MYFILE "$attached\n";
}
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$filename="naverkin-phy.txt";
if(-e $filename)
{
unlink($filename);
}
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
$mech->get("http://kin.naver.com/qna/list.nhn?m=noanswer&dirId=1114&page=1");
#$no=197187698;
$list_cont = $mech->content();
$list_cont=encode("euc-kr", $list_cont);
#print $list_cont;
@link = split(/docId=(\d{9})/, $list_cont);
for ($i=1; $i<=$#link; $i++){
if ($i%2 == 1){
push(@no, $link[$i]);
}
}
@no = sort {$a <=> $b} @no; # 1,2,3 순으로 정렬; Ascending
for ($i=1; $i<=$#no; $i++){
print $no[$i]." article is extracted...\n";
# paste from url of webbrowser manually later modify
$mech->get("http://kin.naver.com/qna/detail.nhn?d1id=11&dirId=1114&docId=$no[$i]");
$cont = $mech->content();
$cont=encode("euc-kr", $cont);
#@temp = split(/og:url/, $cont);
#@temp = split(/science&no=/, $temp[1]);
#@temp = split(/&page/, $temp[1]);
@temp = split(/tit_cont/, $cont);
@temp = split(/recom_q/, $temp[1]);
@temp = split(/img/, $temp[0]);
@temp = split(/dl/, $temp[0]);
$subject = $temp[0];
$subject =~ s/">//g;
$subject =~ s/h3>//g;
$subject =~ s/<//g;
$subject =~ s/\///g;
$subject =~ s/^\s+//g;
$subject =~ s/\s+$//g;
$subject = "subject: ".$subject;
@temp = split(/tit_cont/, $cont);
@temp = split(/recom_q/, $temp[1]);
@temp = split(/<dl>/, $temp[0]);
@temp = split(/<\/dl>/, $temp[1]);
@temp = split(/<dt>/, $temp[0]);
@temp = split(/<\/dt>/, $temp[1]);
$name = $temp[0];
$name =~ s/^\s+//g;
$name =~ s/\s+$//g;
$name = "name: ".$name;
@temp = split(/본문/, $cont);
@temp = split(/게시중단 안내/, $temp[3]);
$out = $temp[1];
$out =~ s/!<--$//;
$out =~ s/<\/div>//;
$out =~ s/\!<--//;
$memo = $out;
#print $memo;
$memo = "memo: ".$memo;
@temp = split(/본문/, $cont);
@temp = split(/게시중단 안내/, $temp[3]);
@img_url = split(/src="/,$temp[1]);
@img_url = split(/\?type/,$img_url[1]);
#print $img_url[0];
$img_url[0]=~ m/jpg|png|JPG|PNG/;
if ($img_url[0]){
$img_type = $&;
$mech->mirror($img_url[0], $no.".".$img_type);
}
$attached = "file:".$no.".".$img_type;
open MYFILE, ">>", "naverkin-phy.txt" or die ;
print MYFILE "$no[$i]";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
print MYFILE "$attached\n";
}
get bgm from bgmstore
use LWP::UserAgent;
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
if (-e "bgmstore.txt"){
unlink("bgmstore.txt");
}
$mech->get("http://bgmstore.net/?q_type=category&q=%EC%9C%A0%EB%A8%B8");
@link = $mech->find_all_links( url_regex => qr/view/);
for $new_link (@link){
$url = $new_link->url_abs();
$no++;
if ($no % 2 == 0 ){
print $url;
$mech->get($url);
$cont = $mech->content();
print $no." article is extracted...\n";
@files=();
$cont=encode("euc-kr", $cont);
@temp = split(/titleBox/, $cont);
@temp = split(/<span/, $temp[1]);
$subject = $temp[0];
$subject =~ s/clearfix">//;
print $subject;
$name = "땡초";
@mp3 = $mech->find_all_links( url_regex => qr/mp3/);
print $mp3[0]->url_abs();
$filename = $subject;
$filename =~ s/,//g;
$filename =~ s/\?//g;
$filename =~ s/\s+//g;
print $filename;
$mech->mirror($mp3[0]->url_abs(), $filename.".mp3");
$name = "name: ".$name;
$subject = "subject: ".$subject;
$memo = "memo: ".$memo;
open MYFILE, ">>", "bgmstore.txt" or die ;
print MYFILE "$no";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
}
}
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
if (-e "bgmstore.txt"){
unlink("bgmstore.txt");
}
$mech->get("http://bgmstore.net/?q_type=category&q=%EC%9C%A0%EB%A8%B8");
@link = $mech->find_all_links( url_regex => qr/view/);
for $new_link (@link){
$url = $new_link->url_abs();
$no++;
if ($no % 2 == 0 ){
print $url;
$mech->get($url);
$cont = $mech->content();
print $no." article is extracted...\n";
@files=();
$cont=encode("euc-kr", $cont);
@temp = split(/titleBox/, $cont);
@temp = split(/<span/, $temp[1]);
$subject = $temp[0];
$subject =~ s/clearfix">//;
print $subject;
$name = "땡초";
@mp3 = $mech->find_all_links( url_regex => qr/mp3/);
print $mp3[0]->url_abs();
$filename = $subject;
$filename =~ s/,//g;
$filename =~ s/\?//g;
$filename =~ s/\s+//g;
print $filename;
$mech->mirror($mp3[0]->url_abs(), $filename.".mp3");
$name = "name: ".$name;
$subject = "subject: ".$subject;
$memo = "memo: ".$memo;
open MYFILE, ">>", "bgmstore.txt" or die ;
print MYFILE "$no";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
}
}
2014년 5월 30일 금요일
우분투에서 루트 권한으로 명령 실행
우분투에서 루트 권한으로 명령을 실행하기 위해서는 root password가 설정되어 있어야 한다.
sudo passwd root
이후 sudo 명령을 사용할 수 있다
sudo passwd root
이후 sudo 명령을 사용할 수 있다
perl mechanize example
use LWP::UserAgent;
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
$filename = "ilbe.txt";
if(-e $filename)
{
unlink($filename);
}
$mech->get("http://www.ilbe.com/ilbe");
@link = $mech->find_all_links( url_regex => qr/\d{10}/);
for $new_link (@link){
$url = $new_link->url_abs();
$no = $url;
$no =~ m/\d{10}/;
$no = $&;
$mech->get($url);
$cont = $mech->content();
print $no." article is extracted...\n";
@files=();
# paste from url of webbrowser manually later modify
#@temp = split(/og:url/, $cont);
#@temp = split(/science&no=/, $temp[1]);
#@temp = split(/&page/, $temp[1]);
#$no = $temp[0];
$cont=encode("euc-kr", $cont);
@temp = split(/author/, $cont);
@temp = split(/<\/div>/, $temp[1]);
@temp = split(/<\/div>/, $temp[0]);
@temp = split(/margin-right:3px;/, $temp[0]);
$name = $temp[1];
$name =~ s/"//;
$name =~ s/\/>//;
$name =~ s/^\s+//;
@temp = split(/<\/span>/, $name);
$name =~ s/\s+$//;
$name = $temp[0];
#print $name;
@temp = split(/기사 제목/, $cont);
@temp = split(/-->/, $temp[1]);
@temp = split(/<!--/, $temp[1]);
$subject = $temp[0];
print $subject;
@temp = split(/기사 본문/, $cont);
@temp = split(/serverLog/, $temp[1]);
$memo = $temp[0];
$memo =~ s/-->//;
$memo =~ s/^\s+//;
#print $memo;
@img = $mech->find_all_links( text_regex => qr/png/i );
$i = 0;
for my $img_url (@img) {
$i++;
print $img_url->url_abs;
$mech->mirror($img_url->url_abs, $no."-".$i.".png");
push (@files, $no."-".$i.".png");
}
@img = $mech->find_all_links( text_regex => qr/jpg/i );
for my $img_url (@img) {
$i++;
print $img_url->url_abs;
$mech->mirror($img_url->url_abs, $no."-".$i.".jpg");
push (@files, $no."-".$i.".jpg");
#Opens FROM_DIR, ao I can read from it
}
$attached = "file:";
for ($i=0; $i<=$#files; $i++){
$attached = $attached.$files[$i]." ";
}
$name = "name: ".$name;
$subject = "subject: ".$subject;
$memo = "memo: ".$memo;
open MYFILE, ">>$filename" or die ;
print MYFILE "$no";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
print MYFILE "$attached\n";
}
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
$filename = "ilbe.txt";
if(-e $filename)
{
unlink($filename);
}
$mech->get("http://www.ilbe.com/ilbe");
@link = $mech->find_all_links( url_regex => qr/\d{10}/);
for $new_link (@link){
$url = $new_link->url_abs();
$no = $url;
$no =~ m/\d{10}/;
$no = $&;
$mech->get($url);
$cont = $mech->content();
print $no." article is extracted...\n";
@files=();
# paste from url of webbrowser manually later modify
#@temp = split(/og:url/, $cont);
#@temp = split(/science&no=/, $temp[1]);
#@temp = split(/&page/, $temp[1]);
#$no = $temp[0];
$cont=encode("euc-kr", $cont);
@temp = split(/author/, $cont);
@temp = split(/<\/div>/, $temp[1]);
@temp = split(/<\/div>/, $temp[0]);
@temp = split(/margin-right:3px;/, $temp[0]);
$name = $temp[1];
$name =~ s/"//;
$name =~ s/\/>//;
$name =~ s/^\s+//;
@temp = split(/<\/span>/, $name);
$name =~ s/\s+$//;
$name = $temp[0];
#print $name;
@temp = split(/기사 제목/, $cont);
@temp = split(/-->/, $temp[1]);
@temp = split(/<!--/, $temp[1]);
$subject = $temp[0];
print $subject;
@temp = split(/기사 본문/, $cont);
@temp = split(/serverLog/, $temp[1]);
$memo = $temp[0];
$memo =~ s/-->//;
$memo =~ s/^\s+//;
#print $memo;
@img = $mech->find_all_links( text_regex => qr/png/i );
$i = 0;
for my $img_url (@img) {
$i++;
print $img_url->url_abs;
$mech->mirror($img_url->url_abs, $no."-".$i.".png");
push (@files, $no."-".$i.".png");
}
@img = $mech->find_all_links( text_regex => qr/jpg/i );
for my $img_url (@img) {
$i++;
print $img_url->url_abs;
$mech->mirror($img_url->url_abs, $no."-".$i.".jpg");
push (@files, $no."-".$i.".jpg");
#Opens FROM_DIR, ao I can read from it
}
$attached = "file:";
for ($i=0; $i<=$#files; $i++){
$attached = $attached.$files[$i]." ";
}
$name = "name: ".$name;
$subject = "subject: ".$subject;
$memo = "memo: ".$memo;
open MYFILE, ">>$filename" or die ;
print MYFILE "$no";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
print MYFILE "$attached\n";
}
피드 구독하기:
글 (Atom)



