#!/usr/bin/perl -w use strict; use warnings; my $url = "https://deutsch.rt.com/inland/"; my $path = "/home/me/RT/rt_scrape.html"; open PATH, "> $path" or die $!; my $counter; while (defined $url) { my %hash; my $html = qx(curl "$url"); undef($url); if ($html =~ m/href="(\/listing\/category.inland\/prepare\/last-news\/ +\d+">)Weiter/) { $url = "www.deutsch.rt.com" . $1; } my @row = split(/\n/,$html); foreach (@row){ if ($html =~ m/href="(\/inland\/\d+\-.*?\/" class="cover__link + link ">)/g) { my $articles_url = "https://deutsch.rt.com/" . $1; $hash{$articles_url} = 1; } } foreach (keys %hash){ $counter++; my $article = qx(curl $_); open PATH, "> /home/me/RT/$counter.txt" or die $!; print "\n\tFetching\n$_\n"; print PATH "$article"; close PATH; } }

I am a Perl newbie and I am trying to scrape the archive with all of the inland articles. Some articles are downloaded, but the files are empty.

The error message in the terminal is: "Fetching https://deutsch.rt.com//inland/50091-bundesregierung-giftgasvorwurfe-assad-saudi-arabien/" class="cover__link link "> sh: 1: Syntax error: Unterminated quoted string"

So my script starts downloading the articles, but then something happens.. Can you please help me to write a functional script?


In reply to Scraping a website - Unterminated quoted string by Staralfur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.