随机使用不同代理和用户代理的智能屏幕抓取?

发布于 2024-09-01 03:33:09 字数 396 浏览 3 评论 0原文

我想从 http://abc.com/view_page.aspx?ID="rel="nofollow noreferrer">http://abc.com/view_page.aspx? 下载一些 HTML 页面ID= ID 来自不同数字的数组。

我有兴趣访问此 URL 的多个实例并使用不同的代理 IP/端口将文件保存为 [ID].HTML。

我想使用不同的用户代理,并且我想随机化每次下载之前的等待时间。

这样做的最佳方法是什么? urllib2? pycURL?卷曲?对于手头的任务,你更喜欢什么?

请指教。谢谢你们!

I want to download few HTML pages from http://abc.com/view_page.aspx?ID= The ID is from an array of different numbers.

I would be interested in visiting multiple instances of this URL and saving the file as [ID].HTML using different proxy IP/ports.

I want to use different user-agents and I want to randomize the wait times before each download.

What is the best way of doing this? urllib2? pycURL? cURL? What do you prefer for the task at hand?

Please advise. Thanks guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请叫√我孤独 2024-09-08 03:33:09

使用类似的东西:

import urllib2
import time
import random

MAX_WAIT = 5
ids = ...
agents = ...
proxies = ...

for id in ids:
    url = 'http://abc.com/view_page.aspx?ID=%d' % id
    opener = urllib2.build_opener(urllib2.ProxyHandler({'http' : proxies[0]}))
    html = opener.open(urllib2.Request(url, None, {'User-agent': agents[0]})).read()
    open('%d.html' % id, 'w').write(html)
    agents.append(agents.pop()) # cycle
    proxies.append(proxies.pop())
    time.sleep(MAX_WAIT*random.random())

Use something like:

import urllib2
import time
import random

MAX_WAIT = 5
ids = ...
agents = ...
proxies = ...

for id in ids:
    url = 'http://abc.com/view_page.aspx?ID=%d' % id
    opener = urllib2.build_opener(urllib2.ProxyHandler({'http' : proxies[0]}))
    html = opener.open(urllib2.Request(url, None, {'User-agent': agents[0]})).read()
    open('%d.html' % id, 'w').write(html)
    agents.append(agents.pop()) # cycle
    proxies.append(proxies.pop())
    time.sleep(MAX_WAIT*random.random())
挽梦忆笙歌 2024-09-08 03:33:09

使用unix工具wget。它可以选择指定自定义用户代理和每次页面检索之间的延迟。

您可以查看 wget(1) 手册页以获取更多信息。

Use unix tool wget. It has option to specify custom user-agent and delay between each retrieval of the page.

You can see wget(1) man page for more information.

不醒的梦 2024-09-08 03:33:09

如果您不想使用开放代理,请查看 ProxyMesh,它可以为您进行 IP 轮换/随机化。

If you don't want to use open proxies, checkout ProxyMesh, which does IP rotation/randomization for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文