Lisa1993 has asked for the wisdom of the Perl Monks concerning the following question:
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.However, when I try to run the code (from my windows command centre) I get the following error message: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);
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!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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question regarding web scraping
by hippo (Archbishop) on Oct 22, 2016 at 14:37 UTC | |
by Lisa1993 (Acolyte) on Oct 22, 2016 at 15:27 UTC | |
|
Re: Question regarding web scraping
by Corion (Patriarch) on Oct 22, 2016 at 14:39 UTC | |
by Gangabass (Vicar) on Oct 23, 2016 at 05:42 UTC | |
by Lisa1993 (Acolyte) on Oct 22, 2016 at 15:30 UTC | |
|
Re: Question regarding web scraping
by Athanasius (Archbishop) on Oct 22, 2016 at 14:58 UTC | |
by Lisa1993 (Acolyte) on Oct 22, 2016 at 15:43 UTC | |
by stevieb (Canon) on Oct 22, 2016 at 16:22 UTC | |
by Lisa1993 (Acolyte) on Oct 23, 2016 at 08:10 UTC | |
by Corion (Patriarch) on Oct 23, 2016 at 08:21 UTC | |
|
Re: Question regarding web scraping
by marto (Cardinal) on Oct 23, 2016 at 08:29 UTC |