{"id":3624,"date":"2024-02-16T15:33:32","date_gmt":"2024-02-17T00:33:32","guid":{"rendered":"https:\/\/crm270s.abramjmeister.com\/?p=3624"},"modified":"2024-02-16T15:33:32","modified_gmt":"2024-02-17T00:33:32","slug":"koreadaily-yellowpage-crawl-parse-process","status":"publish","type":"post","link":"https:\/\/crm270s.mycpamytax.com\/?p=3624","title":{"rendered":"KoreaDaily Yellowpage Crawl \/ Parse Process"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Visit &#8220;KoreaDaily Yelllowpage&#8221; using Firefox<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Choose {\uc2dc\uc560\ud2c0}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\ub2e4\uc6b4\ub85c\ub4dc, &#8220;\uac00 \ub098 \ub2e4 \ub77c \ub9c8 \ubc14 \uc0ac \uc544 \uc790 \ucc28 \uce74 \ud0c0 \ud30c \ud558&#8221; as TEXT file using Firefox.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>US_Cities.txt<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Atlanta\nChicago\nTexas\nWashington_DC\nDenver\nHawaii\nLos_Angeles\nNew_York\nSan_Diego\nSeattle\nSan_Francisco\nLas_Vegas<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>US_Cities.pl<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Open US_Cities.txt for reading\nopen(my $input_fh, '&lt;', 'US_Cities.txt') or die \"Could not open US_Cities.txt: $!\";\n# Open US_Cities_14.txt for writing\nopen(my $output_fh, '&gt;', 'US_Cities_14.txt') or die \"Could not create US_Cities_14.txt: $!\";\n\n# Read each line from US_Cities.txt\nwhile (my $city = &lt;$input_fh&gt;) {\n    chomp $city;  # Remove newline character\n    # Write the city name followed by numbers 01 to 14 to US_Cities_14.txt\n    print $output_fh \"$city\\_01.txt\\n\";\n    print $output_fh \"$city\\_02.txt\\n\";\n    print $output_fh \"$city\\_03.txt\\n\";\n    print $output_fh \"$city\\_04.txt\\n\";\n    print $output_fh \"$city\\_05.txt\\n\";\n    print $output_fh \"$city\\_06.txt\\n\";\n    print $output_fh \"$city\\_07.txt\\n\";\n    print $output_fh \"$city\\_08.txt\\n\";\n    print $output_fh \"$city\\_09.txt\\n\";\n    print $output_fh \"$city\\_10.txt\\n\";\n    print $output_fh \"$city\\_11.txt\\n\";\n    print $output_fh \"$city\\_12.txt\\n\";\n    print $output_fh \"$city\\_13.txt\\n\";\n    print $output_fh \"$city\\_14.txt\\n\";\n    print $output_fh \"\\n\";  # Add a blank line between cities\n}\n\n# Close the file handles\nclose $input_fh;\nclose $output_fh;\n\nprint \"US_Cities_14.txt has been created.\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>KoreaDaily.pl (this code extracts each business type URL at KoreaDaily Yellowpage)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Define the output file name\nmy $output_file = 'KoreaDaily.txt';\n\n# Open the output file for writing\nopen(my $fh_out, '&gt;', $output_file) or die \"Could not open file '$output_file' for writing: $!\";\n\n# Loop through files Atlanta_01.txt to Atlanta_13.txt\nfor my $file_number (1..14) {\n    my $input_file = \"Seattle_\" . sprintf(\"%02d\", $file_number) . \".txt\";\n    \n    # Open the current input file for reading\n    open(my $fh_in, '&lt;', $input_file) or die \"Could not open file '$input_file': $!\";\n\n    # Iterate through each line of the current input file\n    while (my $line = &lt;$fh_in&gt;) {\n        # Check if the line contains 'cat_code='\n        if ($line =~ \/cat_code=\/) {\n            # Write the line to the output file\n            print $fh_out $line;\n        }\n    }\n\n    # Close the current input file handle\n    close($fh_in);\n}\n\n# Close the output file handle\nclose($fh_out);\n\nprint \"Extraction completed. Results saved in '$output_file'.\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>KoreaDaily_URL.pl (this code removes &lt; and &gt; from KoreaDaily.txt)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\nuse strict;\nuse warnings;\n\n# Define the input and output file names\nmy $input_file = \"KoreaDaily.txt\";\nmy $output_file = \"KoreaDaily_URL.txt\";\n\n# Open the input file for reading\nopen my $input_fh, '&lt;', $input_file or die \"Cannot open file $input_file: $!\";\n\n# Open the output file for writing\nopen my $output_fh, '&gt;', $output_file or die \"Cannot open file $output_file: $!\";\n\n# Loop through each line of the input file\nwhile (my $line = &lt;$input_fh&gt;) {\n    chomp $line; # Remove newline character\n    my @matches = $line =~ \/&lt;(&#91;^&gt;]+)&gt;\/g; # Extract content between &lt; and &gt; using regex\n\n    # Write the extracted content to the output file\n    foreach my $match (@matches) {\n        print $output_fh \"$match\\n\";\n    }\n}\n\n# Close the files\nclose $input_fh;\nclose $output_fh;\n\nprint \"Extraction completed. Extracted content saved in $output_file.\\n\";\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>KoreaDaily_URL_biz.pl (removes none biz name URL)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Input and output file names\nmy $input_file = 'KoreaDaily_URL.txt';\nmy $output_file = 'KoreaDaily_URL_biz.txt';\n\n# Open input and output files\nopen(my $input_fh, '&lt;', $input_file) or die \"Could not open file '$input_file': $!\";\nopen(my $output_fh, '&gt;', $output_file) or die \"Could not create file '$output_file': $!\";\n\n# Read input file line by line\nwhile (my $line = &lt;$input_fh&gt;) {\n    # Check if the line does not end with 'sort=N'\n    unless ($line =~ \/sort=N$\/) {\n        # Write the line to the output file\n        print $output_fh $line;\n    }\n}\n\n# Close file handles\nclose($input_fh);\nclose($output_fh);\n\nprint \"Filtered URLs saved to '$output_file'.\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>mecha.pl (this code mechanize each page)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\nuse Encode;  # To handle encoding issues\nuse WWW::Mechanize;\n\n# Read URLs from the text file\nmy $filename = 'onlypage6_modified.txt';\n\n# Create a new WWW::Mechanize object\nmy $mech = WWW::Mechanize->new();\n\n# Open the text file\nopen(my $fh, '&lt;', $filename) or die \"Could not open file '$filename' $!\";\n\n# Initialize page number\nmy $page_num = 1;\n\n# Loop through each URL in the file\nwhile (my $url = &lt;$fh>) {\n    chomp $url;  # Remove newline character\n\n    # Check if the URL contains \/list\/list.asp\n    next unless $url =~ m|\/list\/list\\.asp|;\n\n    # Try to visit the URL, skip on failure\n    eval {\n        $mech->get($url);\n    };\n    if ($@) {\n        warn \"Failed to get $url: $@\";\n        next; # Skip to the next URL on failure\n    }\n\n    # Get the content of the current page\n    my $content = $mech->content();\n\n    # Save the content to a file with EUC-KR encoding\n    my $filename = sprintf(\"%d.html\", $page_num);\n    open(my $fh_out, '>:encoding(EUC-KR)', $filename) or die \"Could not open file '$filename' for writing: $!\";\n    print $fh_out $content;\n    close $fh_out;\n\n    # Find pagination links and click on them to navigate through pages\n    my @pagination_links = $mech->find_all_links(url_regex => qr\/page=\/i);\n    for my $link (@pagination_links) {\n        # Try to visit the pagination link, skip on failure\n        eval {\n            $mech->get($link->url);\n        };\n        if ($@) {\n            warn \"Failed to get pagination link $link->url: $@\";\n            next; # Skip to the next pagination link on failure\n        }\n\n        my $content = $mech->content();\n        $page_num++;\n        my $filename = sprintf(\"%d.html\", $page_num);\n        open(my $fh_out, '>:encoding(EUC-KR)', $filename) or die \"Could not open file '$filename' for writing: $!\";\n        print $fh_out $content;\n        close $fh_out;\n    }\n\n    # Increment page number\n    $page_num++;\n}\n\n# Close the file handle\nclose($fh);\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>filename.pl (come up with mechanized file list file)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\nuse strict;\nuse warnings;\n\n# Open the output file for writing\nopen my $output_fh, '&gt;', \"file_names.txt\" or die \"Cannot open file file_names.txt for writing: $!\";\n\n# Generate file names from 1.html to 481.html and write them to the output file\nfor my $i (1..300) {\n    my $file_name = \"$i.html\";\n    print $output_fh \"$file_name\\n\";\n}\n\n# Close the file\nclose $output_fh;\n\nprint \"File names generated and saved to file_names.txt\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>page_extract.pl (extracts mechanizable file names on downloaded file)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Define the input and output filenames\nmy $input_filename = 'file_names.txt';\nmy $output_filename = 'ahrefextract.txt';\n\n# Open the output file for writing\nopen(my $fh_out, '&gt;', $output_filename) or die \"Could not open file '$output_filename' $!\";\n\n# Open the input file containing the list of HTML files\nopen(my $fh_in, '&lt;', $input_filename) or die \"Could not open file '$input_filename' $!\";\n\n# Loop through each HTML file in the input list\nwhile (my $html_file = &lt;$fh_in&gt;) {\n    chomp $html_file;  # Remove newline character\n\n    # Open the HTML file for reading\n    open(my $fh_html, '&lt;', $html_file) or die \"Could not open file '$html_file' $!\";\n\n    # Read the HTML content from the file\n    my $html_content = do { local $\/; &lt;$fh_html&gt; };\n\n    # Close the HTML file handle\n    close($fh_html);\n\n    # Extract URLs matching the specified pattern\n    while ($html_content =~ m\/&lt;a\\s+&#91;^&gt;]*?href=\"(&#91;^\"]*\\\/list\\\/list\\.asp&#91;^\"]*)\"\/ig) {\n        my $url = $1;\n        print $fh_out \"URL: $url\\n\";  # Write the extracted URL to the output file\n    }\n}\n\n# Close the file handles\nclose($fh_in);\nclose($fh_out);\n\nprint \"Extraction complete. Extracted URLs saved in $output_filename\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>page6extract.pl <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Input and output filenames\nmy $input_filename = 'ahrefextract.txt';\nmy $output_filename = 'page_6_extract.txt';\n\n# Open the input file for reading\nopen(my $fh_in, '&lt;', $input_filename) or die \"Could not open file '$input_filename' $!\";\n\n# Open the output file for writing\nopen(my $fh_out, '&gt;', $output_filename) or die \"Could not open file '$output_filename' $!\";\n\n# Loop through each line in the input file\nwhile (my $line = &lt;$fh_in&gt;) {\n    # Check if the line contains 'page=6'\n    if ($line =~ \/page=6\/) {\n        # Write the line to the output file\n        print $fh_out $line;\n    }\n}\n\n# Close the file handles\nclose($fh_in);\nclose($fh_out);\n\nprint \"Extraction complete. Lines containing 'page=6' saved in $output_filename\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>page6unique.pl (come up with unique lines from extrated)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Input and output filenames\nmy $input_filename = 'page_6_extract.txt';\nmy $output_filename = 'onlypage6.txt';\n\n# Hash to store unique lines\nmy %unique_lines;\n\n# Open the input file for reading\nopen(my $fh_in, '&lt;', $input_filename) or die \"Could not open file '$input_filename' $!\";\n\n# Loop through each line in the input file\nwhile (my $line = &lt;$fh_in&gt;) {\n    # Remove leading and trailing whitespace\n    $line =~ s\/^\\s+|\\s+$\/\/g;\n\n    # Add the line to the hash (keys are unique)\n    $unique_lines{$line} = 1;\n}\n\n# Close the input file handle\nclose($fh_in);\n\n# Open the output file for writing\nopen(my $fh_out, '&gt;', $output_filename) or die \"Could not open file '$output_filename' $!\";\n\n# Write unique lines to the output file\nforeach my $unique_line (keys %unique_lines) {\n    print $fh_out \"$unique_line\\n\";\n}\n\n# Close the output file handle\nclose($fh_out);\n\nprint \"Unique lines from $input_filename saved in $output_filename\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>onlypage6_modified.pl (update url)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/perl\n\nuse strict;\nuse warnings;\n\n# Input and output file names\nmy $input_file = 'onlypage6.txt';\nmy $output_file = 'onlypage6_modified.txt';\n\n# Open input and output files\nopen(my $input_fh, '&lt;', $input_file) or die \"Could not open file '$input_file': $!\";\nopen(my $output_fh, '&gt;', $output_file) or die \"Could not create file '$output_file': $!\";\n\n# Read input file line by line\nwhile (my $line = &lt;$input_fh&gt;) {\n    # Replace 'URL: \/list' with 'http:\/\/yp.koreadaily.com\/list'\n    $line =~ s\/URL: \\\/list\/http:\\\/\\\/yp.koreadaily.com\\\/list\/;\n    # Write the modified line to the output file\n    print $output_fh $line;\n}\n\n# Close file handles\nclose($input_fh);\nclose($output_fh);\n\nprint \"URLs modified and saved to '$output_file'.\\n\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>run above again for page=11, page=16, page=21, etc.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>and run mecha.pl accordingly again.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visit &#8220;KoreaDaily Yelllowpage&#8221; using Firefox Choose {\uc2dc\uc560\ud2c0} \ub2e4\uc6b4\ub85c\ub4dc, &#8220;\uac00 \ub098 \ub2e4 \ub77c \ub9c8 \ubc14 \uc0ac \uc544 \uc790 \ucc28 \uce74 \ud0c0 \ud30c \ud558&#8221; as TEXT file using Firefox. US_Cities.txt US_Cities.pl KoreaDaily.pl (this code extracts each business type URL at KoreaDaily Yellowpage) KoreaDaily_URL.pl (this code removes &lt; and &gt; from KoreaDaily.txt) KoreaDaily_URL_biz.pl (removes none biz name URL) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/crm270s.mycpamytax.com\/?p=3624\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;KoreaDaily Yellowpage Crawl \/ Parse Process&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[26,42],"tags":[],"class_list":["post-3624","post","type-post","status-publish","format-standard","hentry","category-codes","category--yellowpage"],"_links":{"self":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/3624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3624"}],"version-history":[{"count":0,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/3624\/revisions"}],"wp:attachment":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}