-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.pm
52 lines (44 loc) · 970 Bytes
/
search.pm
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
package search;
use WWW::Mechanize;
sub init {
my $mech = WWW::Mechanize->new();
$mech->agent_alias("Linux Mozilla");
# $mech->agent("Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0");
$mech->timeout(12);
$mech->default_header('Accept-Encoding' => scalar HTTP::Message::decodable());
$mech;
}
sub search {
my $q = shift;
my $mech = init();
eval {
$mech->get("https://html.duckduckgo.com/html");
$mech->submit_form(
form_number => 1,
fields => {
"q" => $q,
}
);
};
return $mech;
}
sub search_yahoo {
my $q = shift;
my $mech = init();
eval {
$mech->get("https://fr.search.yahoo.com/search");
$mech->submit_form(
form_number => 1,
fields => {
"p" => $q,
"fr" => "yfp-search-sb"
}
);
};
my $html = $mech->content;
$html =~ s/href="https?:\/\/f?r.search.yahoo.com.+?RU=(.+?)\/.+?"/href="$1"/g;
$html =~ s/%(..)/chr(hex($1))/ge;
$mech->update_html($html);
return $mech;
}
1;