-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebScraping.1.12.pl
More file actions
executable file
·57 lines (33 loc) · 1.25 KB
/
Copy pathwebScraping.1.12.pl
File metadata and controls
executable file
·57 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
#Basic built-in functions
#1. print and comment
#2. open a file.
#open file handle one > is overwrite, two >> is append
open (FILE, ">", "c:/temp/writefile.txt");
my @array=("Hello There","Mr Bond","Shaken not Stirred");
foreach my $element (@array) {
print "$element\n";
#print to the file
print FILE "$element\n";
}
close (FILE);
#what if you want to open a web page? Need to use a module.
#open my $fh, '>/home/john/tmp/ownrate.html' or die "$!";
my $url = 'http://www.census.gov/hhes/www/housing/census/historic/ownrate.html';
print getstore( $url, 'c:/temp/ownrate.html' );
open (INFILE ,"<", "c:/temp/ownrate.html") or die "$!";
while (<INFILE>) {
#add another IF statement to get the homeownership rates by year
if($_=~/HOMEOWNERSHIP RATES:\s\s(\d\d\d\d)/) {
print "$1\t";
}
#adding a regex match "mr"
if($_=~/^(DC)\s\s\s\s(\d\d\.\d)\%/) {
#$1 is the first capture group, and so forth
#put a breakpoint here. ... understand what's going on, loop through a three times. why the extra mr? OK, need an if..then
print "$1\t$2\n";
}
}
close (INFILE);