]> git.donarmstrong.com Git - bin.git/commitdiff
find the link first, because back doesnt always work properly
authorDon Armstrong <don@donarmstrong.com>
Mon, 28 Mar 2016 22:51:15 +0000 (15:51 -0700)
committerDon Armstrong <don@donarmstrong.com>
Mon, 28 Mar 2016 22:51:15 +0000 (15:51 -0700)
jobs_to_org

index 81883d1c1bff7f9b80d6f74cc29c2f683e1ec2fc..d76392fa12acf57d5e45a50ba93f8c388025ccb5 100755 (executable)
@@ -118,9 +118,11 @@ my %sites =
      higheredjobs => {url => 'https://www.higheredjobs.com/search/advanced_action.cfm?JobCat=113&JobCat=259&JobCat=99&JobCat=100&JobCat=108&JobCat=107&PosType=1&InstType=1&InstType=2&InstType=3&Keyword=&Remote=1&Remote=2&Region=&Submit=Search+Jobs',
                       next_selector_tree => [class => 'js-click-submit',
                                              href => qr{advanced_action\.cfm},
-                                             sub {$_[0]->look_down(src => qr/active-right/) ||
-                                                      return 0;
-                                                  return 1;
+                                             sub {return 1
+                                                      if defined
+                                                      $_[0]->look_down(src =>
+                                                                       qr/active-right/);
+                                                  return 0;
                                               },
                                             ],
                       job_selector => [url_regex => qr{^details.cfm\?JobCode=\d+},
@@ -166,6 +168,18 @@ sub get_jobs {
         my %seen;
         my @job_urls = grep { ! $seen{ $_->URI()->abs() }++ }
             $m->find_all_links(@{$s->{job_selector}});
+        my $link;
+        if (exists $s->{next_selector}) {
+            ($link) = map {$_->URI()->abs()}
+                $m->find_all_links(@{$s->{next_selector}});
+        } elsif (exists $s->{next_selector_tree}) {
+            $link = $m->tree->look_down(@{$s->{next_selector_tree}});
+            if (not defined $link) {
+                $m->tree->dump;
+            }
+            die "Unable to find next link" unless defined $link;
+            $link = $link->attr('href');
+        }
         for my $j_u (sort @job_urls) {
             $m->get($j_u) or next;
             my $university = 'No university';
@@ -191,16 +205,9 @@ sub get_jobs {
                 $position = $m->tree->look_down(@{$s->{position}})->as_text();
             };
             print format_job($university,$position,$j_u->URI->abs(),$description,$date);
-            $m->back();
-        }
-        if (exists $s->{next_selector}) {
-            $m->follow_link(@{$s->{next_selector}}) or die "Unable to find next link";
-        } elsif (exists $s->{next_selector_tree}) {
-            my $link = $m->tree->look_down(@{$s->{next_selector_tree}}) or
-                die "Unable to find next link";
-            $m->get($link->attr('href')) or
-                die "Unable to get next page";
+            $m->back() or die "Unable to go back";
         }
+        $m->get($link);
     }
 }