scrapy/nginx 服务带有http 验证,怎样使用curl 请求

参考:

https://www.jianshu.com/p/c98892a2c561

爬虫服务免不了需要定时启动,就需要crontab+curl 来触发,但是curl 怎样发送带验证的请求.

有些网域需要 HTTP 认证,这时 curl 需要用到 --user 或者 -u 参数。

$ curl --user name:password example.com

如果不使用验证直接请求网站会有如下提示:

<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>

使用验证了以后就没有问题:

curl --user user:password abc.com:6800

<html>
<head><title>Scrapyd</title></head>
<body>
<h1>Scrapyd</h1>
<p>Available projects: <b>scrapy_rere</b></p>
<ul>
<li><a href="/jobs">Jobs</a></li>
<li><a href="/items/">Items</a></li>
<li><a href="/logs/">Logs</a></li>
<li><a href="http://scrapyd.readthedocs.org/en/latest/">Documentation</a></li>
</ul>

<h2>How to schedule a spider?</h2>

<p>To schedule a spider you need to use the API (this web UI is only for
monitoring)</p>

<p>Example using <a href="http://curl.haxx.se/">curl</a>:</p>
<p><code>curl http://localhost:6800/schedule.json -d project=default -d spider=somespider</code></p>

<p>For more information about the API, see the <a href="http://scrapyd.readthedocs.org/en/latest/">Scrapyd documentation</a></p>
</body>
</html>

补充说明:

我的scrapy 服务是使用docker搭建的,docker中又使用nginx 代理验证,

posted @ 2020-07-30 15:04  那时一个人  阅读(468)  评论(0)    收藏  举报