鱼C论坛

 找回密码
 立即注册
查看: 2043|回复: 3

爬虫,print网页出问题了

[复制链接]
发表于 2020-2-19 11:37:03 | 显示全部楼层 |阅读模式

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

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

x
别的都没问题,就是print出问题了
  1. import requests
  2. #分析目标网页,确定爬取url路径,headers参数。
  3. base_url='https://tieba.baidu.com/f?ie=utf-8&kw=%E7%BE%8E%E5%A5%B3'#kw后面发生了变化
  4. headers = {
  5.     'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}

  6. response=requests.get(base_url,headers=headers)
  7. html_str=response.text
  8. #html_str=html_str.encoding('utf-8')
  9. print(html_str)
复制代码

捕获.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-19 11:39:11 | 显示全部楼层
不要用 IDLE 运行,双击运行以下程序:

  1. import requests

  2. # 分析目标网页,确定爬取url路径,headers参数。
  3. base_url = 'https://tieba.baidu.com/f?ie=utf-8&kw=%E7%BE%8E%E5%A5%B3'  # kw后面发生了变化
  4. headers = {
  5.     'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) "
  6.                   "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}

  7. response = requests.get(base_url, headers=headers)
  8. html_str = response.text
  9. # html_str=html_str.encoding('utf-8')
  10. print(html_str)
  11. input()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-19 11:39:36 From FishC Mobile | 显示全部楼层
ucs-2是一个和已知的utf8什么的都不一样的编码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-19 12:26:32 | 显示全部楼层
https://fishc.com.cn/thread-102403-1-1.html
巧了,很久以前我也碰到过和你一模一样的问题。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-22 15:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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