python 爬虫,返回404是什么原因造成的?

何时西风止 2019-10-15 04:34:23
URL是一个ts下载地址:https://feifei.feifeizuida.com/20190929/18928_59f5f35b/1000k/hls/ddb0835196f000000.ts。
正常输入访问可以下载文件, 但使用python访问一直返回404。
访问头已经加上,应该是其他原因造成的,刚刚入门python,不明白哪里出问题了。
...全文
3511 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
法师塔设计师 2021-01-05
  • 打赏
  • 举报
回复
引用 3 楼 jmzl 的回复:
https的要模拟浏览器访问才行
一阵见血,感谢!
何时西风止 2019-10-15
  • 打赏
  • 举报
回复
引用 2 楼 Eleven 的回复:

import urllib.request

try:
    file = 'F:/11.ts'
    url = 'https://feifei.feifeizuida.com/20190929/18928_59f5f35b/1000k/hls/ddb0835196f000000.ts'
    urllib.request.urlretrieve(url, file)
except Exception as e:
    print(e)
可以使用,谢谢了。
jmzl 2019-10-15
  • 打赏
  • 举报
回复
import urllib.request import ssl ssl._create_default_https_context = ssl._create_stdlib_context # 网址 url = "http://wap.u33.cc/u44185/2436734.html" headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/51.0.2704.63 Safari/537.36'} req = urllib.request.Request(url=url, headers=headers) res = urllib.request.urlopen(req) data = res.read() data = data.decode('utf-8') # 打印抓取的内容 print(data) # 打印爬取网页的各类信息 print(type(res)) print(res.geturl()) print(res.info()) print(res.getcode())
jmzl 2019-10-15
  • 打赏
  • 举报
回复
https的要模拟浏览器访问才行
Eleven 2019-10-15
  • 打赏
  • 举报
回复

import urllib.request

try:
file = 'F:/11.ts'
url = 'https://feifei.feifeizuida.com/20190929/18928_59f5f35b/1000k/hls/ddb0835196f000000.ts'
urllib.request.urlretrieve(url, file)
except Exception as e:
print(e)
Eleven 2019-10-15
  • 打赏
  • 举报
回复
import urllib.request

try:
file = 'F:/11.ts'
url = 'https://feifei.feifeizuida.com/20190929/18928_59f5f35b/1000k/hls/ddb0835196f000000.ts'
urllib.request.urlretrieve(url, file)
except Exception as e:
print(e)

37,744

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧