如何使用 Perl 从网站下载链接目标?
我刚刚制作了一个脚本来从网站获取链接,然后将它们保存到文本文件中。
现在我正在处理我的正则表达式,因此它将从文本文件中获取 URL 中包含 php?dl=
的链接:
例如:www.example.com/site/admin/a_files .php?dl=33931
这几乎就是您将鼠标悬停在网站上的 dl
按钮上时获得的地址。您可以从中单击下载或“右键单击保存”。
我只是想知道如何实现这一点,必须下载给定地址的内容,这将下载 *.txt
文件。当然,一切都来自剧本。
I just made a script to grab links from a website, and in turn saves them into a text file.
Now I'm working on my regexes so it will grab links which contains php?dl=
in the url from the text file:
E.g.: www.example.com/site/admin/a_files.php?dl=33931
Its pretty much the address you get when you hover over the dl
button on the site. From which you can click to download or "right click save".
I'm just wondering on how to achieve this, having to download the content of the given address which will download a *.txt
file. All from the script of course.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让
WWW::Mechanize
成为你最好的新朋友。原因如下:
/php\?dl=/
)follow_link
方法跟踪这些链接获取
这些链接的目标并将它们保存到文件中,而无需将您想要的链接保存在中间文件中!当您拥有适合工作的正确工具时,生活就会变得甜蜜......
示例
Make
WWW::Mechanize
your new best friend.Here's why:
/php\?dl=/
in this case)follow_link
methodget
the targets of those links and save them to fileAll this without needing to save your wanted links in an intermediate file! Life's sweet when you have the right tool for the job...
Example
您可以使用 LWP::UserAgent:
或者如果您需要文件句柄:
You can download the file with LWP::UserAgent:
Or if you need a filehandle:
老问题,但是当我做快速脚本时,我经常使用“wget”或“curl”和管道。这也许不是跨系统可移植的,但如果我知道我的系统有这些命令中的一个或另一个,那么通常是好的。
例如:
Old question, but when I'm doing quick scripts, I often use "wget" or "curl" and pipe. This isn't cross-system portable, perhaps, but if I know my system has one or the other of these commands, it's generally good.
For example: