Hello everybody,
I am very very new to using Perl (as in have only been using it intermittently for less than a couple of weeks), and I'm having a problem with a very basic web scraping programme.
To cut a long story short, I am taking a university module where the instructor has told us to scrape comments from the website Reddit, so that we can analyse the comments using computational linguistics methods.
He has given us the code below to use. The goal is to get the programme to search for every comment on the page and then to save the comments only in an html file.
use LWP::Simple;
$URL = 'https://www.reddit.com/r/unitedkingdom/comments/58m2hs/i_danie
+l_blake_is_released_today/';
$CONTENT = get($URL);
while ($CONTENT =~ <div class=\"usertext-body may-blank-within md-cont
+ainer \"><div class=\"md\">(.+?)<\/div>
<\/div><\/form><ul class=\"flat-list buttons\"> //gs )
{
$x = "$1";
$y = "$y $x";
}
open(OUT, "">C:/Users/user/perl_tests/reddittest.txt");
print OUT "$y";
close(OUT);
However, when I try to run the code (from my windows command centre) I get the following error message:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\user>perl perl_tests/red1.pl
Scalar found where operator expected at perl_tests/red1.pl line 12, ne
+ar "$x = "
$1"
(Might be a runaway multi-line "" string starting on line 7)
(Missing operator before $1?)
String found where operator expected at perl_tests/red1.pl line 12, ne
+ar "$y = "
"
(Missing semicolon on previous line?)
Scalar found where operator expected at perl_tests/red1.pl line 12, ne
+ar "$y $x"
(Missing operator before $x?)
String found where operator expected at perl_tests/red1.pl line 12, ne
+ar "open(O
UT, ""
(Missing semicolon on previous line?)
String found where operator expected at perl_tests/red1.pl line 15, ne
+ar "open(O
UT, "">C:/Users/user/perl_tests/reddittest.txt""
Can't modify numeric lt (<) in scalar assignment at perl_tests/red1.pl
+ line 12,
near "$x = "$1"
syntax error at perl_tests/red1.pl line 12, near "$x = "$1"
Execution of perl_tests/red1.pl aborted due to compilation errors.
I know that there is probably a very "basic" error in the code, but I'm too inexperienced as of yet to know how to fix it. Any help would be greatly appreciated. Thank you!