分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

玩儿虫那些事(四)—— 使用curl

发布时间:2023-09-06 01:37责任编辑:熊小新关键词:url

目录

  • 一、爬一个简单的网站
  • 二、模拟登录新浪
  • 三、各种请求的发送
  • 四、使用curl
  • 五、模拟登录QQ空间
  • 六、selenium的使用
  • 七、phantomjs的使用
  • 八、开源框架webmagic
  • 九、开源框架scrapy
  • 十、多线程爬取与反爬策略
  • 十一、加密与解密
  • 十二、APP数据抓取
  • 十三、分布式爬虫

1、 发送一个简单的请求,获取页面,并查看请求头

curl https://www.baidu.comcurl https://www.baidu.com --head

2、 下载某一资源

curl https://www.baidu.com/1.png

3、将请求到的文件输出到某个文件中

curl https://www.baidu.com -o baidu.txt

4、 请求需要验证 HTTP authentication

curl -u username:password https://xxxx.com

5、 在配置中进行批量操作

curl -K cmdline.txt https://baidu.com

cmdline.txt

--location--head

(6) 分析请求和响应,并将响应结果保存

curl -v https://baidu.com -o response.txt

执行结果如下

* Rebuilt URL to: http://www.baidu.com/ ?% Total ???% Received % Xferd ?Average Speed ??Time ???Time ????Time ?Current ????????????????????????????????Dload ?Upload ??Total ??Spent ???Left ?Speed ?0 ????0 ???0 ????0 ???0 ????0 ?????0 ?????0 --:--:-- --:--:-- --:--:-- ????0* ??Trying 119.75.213.61...* TCP_NODELAY set ?0 ????0 ???0 ????0 ???0 ????0 ?????0 ?????0 --:--:-- --:--:-- --:--:-- ????0* Connected to www.baidu.com (119.75.213.61) port 80 (#0)> GET / HTTP/1.1> Host: www.baidu.com> User-Agent: curl/7.54.0> Accept: */*>< HTTP/1.1 200 OK< Server: bfe/1.0.8.18< Date: Thu, 18 Jan 2018 17:17:36 GMT< Content-Type: text/html< Content-Length: 2381< Last-Modified: Mon, 23 Jan 2017 13:27:36 GMT< Connection: Keep-Alive< ETag: "588604c8-94d"< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform< Pragma: no-cache< Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/< Accept-Ranges: bytes<{ [2381 bytes data]100 ?2381 ?100 ?2381 ???0 ????0 ??3770 ?????0 --:--:-- --:--:-- --:--:-- ?3767* Connection #0 to host www.baidu.com left intact

7、使用post发送数据

curl -d ‘name=amdini&passwd=123‘ http://example.comcurl -d ‘{json}‘ ?-H ?‘Content-Type:application/json‘ http://example.com

8、对发送数据进行编码

curl --data-urlencode "name=John Doe(Junior)" http://example.com

请求的效果

name=John%20Doe%20%28Junior%29

9、发送multipart类型的数据

请求前的格式可能是这样的

<form action="submit.cgi" method="post" enctype="multipart/form-data">Name: <input type="text" name="person"><br>File: <input type="file" name="secret"><br><input type="submit" value="Submit"></form>

请求方法

可以使用-F--form

 ?curl -F person=anonymous -F secret=@file.txt http://example.com/submit.cgi

请求的效果

--------------------------d74496d66958873eContent-Disposition: form-data; name="person"anonymous--------------------------d74496d66958873eContent-Disposition: form-data; name="secret"; filename="file.txt"Content-Type: text/plaincontents of the file--------------------------d74496d66958873e

玩儿虫那些事(四)—— 使用curl

原文地址:https://www.cnblogs.com/fonxian/p/8314527.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved