【发布时间】:2021-07-15 18:47:37
【问题描述】:
所以我正在研究在 Perl 上使用 Selenium:Chrome 抓取网站,我只是想知道如何从 2017 年到 2021 年下载所有 pdf 文件并将其存储到该网站 https://www.fda.gov/drugs/warning-letters-and-notice-violation-letters-pharmaceutical-companies/untitled-letters-2021 的文件夹中。到目前为止,这就是我所做的
use strict;
use warnings;
use Time::Piece;
use POSIX qw(strftime);
use Selenium::Chrome;
use File::Slurp;
use File::Copy qw(copy);
use File::Path;
use File::Path qw(make_path remove_tree);
use LWP::Simple;
my $collection_name = "mre_zen_test3";
make_path("$collection_name");
#DECLARE SELENIUM DRIVER
my $driver = Selenium::Chrome->new;
#NAVIGATE TO SITE
print "trying to get toc_url\n";
$driver->navigate('https://www.fda.gov/drugs/warning-letters-and-notice-violation-letters-pharmaceutical-companies/untitled-letters-2021');
sleep(8);
#GET PAGE SOURCE
my $toc_content = $driver->get_page_source();
$toc_content =~ s/[^\x00-\x7f]//g;
write_file("toc.html", $toc_content);
print "writing toc.html\n";
sleep(5);
$toc_content = read_file("toc.html");
此脚本仅下载网站的全部内容。希望这里有人可以帮助我并教我。非常感谢。
【问题讨论】:
-
这只是占据主页,而不是你想要的东西。需要访问该 pdf 链接和
click它,然后导航到 2020 年并执行相同操作,等等。我现在不能写,但请参阅 Selenium::Remote::Driver 了解您可以使用的内容(并搜索此站点) -
是的,我正在寻找示例,但我似乎无法理解这些示例。但我会研究更多的例子
-
好吧,就这样吧。我也许也可以发布一些东西......
-
更新了我的帖子,看看。我打算编辑更多
标签: selenium perl selenium-webdriver selenium-chromedriver