鱼C论坛

 找回密码
 立即注册
查看: 1343|回复: 6

[已解决]关于爬虫的一个小问题

[复制链接]
发表于 2020-6-30 16:08:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这里面这个word :hello的目的是干嘛的

  1. import urllib.request
  2. import urllib.parse

  3. data = bytes(urllib.parse.urlencode({'word':'hello'}),encoding = 'utf-8')
  4. print(data)
  5. response = urllib.request.urlopen('http://www.baidu.com',data = data)
  6. html = response.read()
  7. print(html)
复制代码
最佳答案
2020-6-30 16:17:30
这里的'word':'hello'就是POST提交的数据,捕捉到的Request Details如下:
  1. POST / HTTP/1.1
  2. Content-Type: application/x-www-form-urlencoded
  3. Host: www.baidu.com
  4. User-Agent: Python-urllib/3.8
  5. Connection: close
  6. Accept-Encoding: identity
  7. Content-Length: 10

  8. word=hello
复制代码


其实这个POST的数据有点问题,返回内容如下,跳转到百度错误页面了
  1. HTTP/1.1 302 Found
  2. Bdpagetype: 3
  3. Content-Type: text/html
  4. Date: Tue, 30 Jun 2020 08:10:08 GMT
  5. Location: https://www.baidu.com/search/error.html
  6. Server: BWS/1.1
  7. Set-Cookie: BDSVRTM=0; path=/
  8. Traceid: 159350460801994787946390024816122759431
  9. X-Ua-Compatible: IE=Edge,chrome=1
  10. Connection: close
  11. Content-Length: 154

  12. <html>
  13. <head><title>302 Found</title></head>
  14. <body bgcolor="white">
  15. <center><h1>302 Found</h1></center>
  16. <hr><center>nginx</center>
  17. </body>
  18. </html>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-6-30 16:17:30 | 显示全部楼层    本楼为最佳答案   
这里的'word':'hello'就是POST提交的数据,捕捉到的Request Details如下:
  1. POST / HTTP/1.1
  2. Content-Type: application/x-www-form-urlencoded
  3. Host: www.baidu.com
  4. User-Agent: Python-urllib/3.8
  5. Connection: close
  6. Accept-Encoding: identity
  7. Content-Length: 10

  8. word=hello
复制代码


其实这个POST的数据有点问题,返回内容如下,跳转到百度错误页面了
  1. HTTP/1.1 302 Found
  2. Bdpagetype: 3
  3. Content-Type: text/html
  4. Date: Tue, 30 Jun 2020 08:10:08 GMT
  5. Location: https://www.baidu.com/search/error.html
  6. Server: BWS/1.1
  7. Set-Cookie: BDSVRTM=0; path=/
  8. Traceid: 159350460801994787946390024816122759431
  9. X-Ua-Compatible: IE=Edge,chrome=1
  10. Connection: close
  11. Content-Length: 154

  12. <html>
  13. <head><title>302 Found</title></head>
  14. <body bgcolor="white">
  15. <center><h1>302 Found</h1></center>
  16. <hr><center>nginx</center>
  17. </body>
  18. </html>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-30 16:22:50 | 显示全部楼层
post提交的数据呀,你post总得post个什么东西吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-6-30 16:24:49 | 显示全部楼层
comeheres 发表于 2020-6-30 16:17
这里的'word':'hello'就是POST提交的数据,捕捉到的Request Details如下:

这个内容你是打印出来的还是自己去网页的开发者人员工具里面复制来的?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-30 16:26:34 | 显示全部楼层
小甲鱼的铁粉 发表于 2020-6-30 16:24
这个内容你是打印出来的还是自己去网页的开发者人员工具里面复制来的?

HTTP Debugger抓取的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-6-30 16:27:08 | 显示全部楼层

能个让我看一下你的代码吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-30 16:34:25 | 显示全部楼层
小甲鱼的铁粉 发表于 2020-6-30 16:27
能个让我看一下你的代码吗?

代码就是你贴的代码,然后打开HTTP Debugger,再运行代码,就能捕捉到数据了

Snipaste_2020-06-30_16-33-07.png

Snipaste_2020-06-30_16-34-12.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-3 17:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表