python requests 无法获取 youtube 的内容

2015 年 1 月 7 日
 cdwyd
RT,代码如下:

import requests

session = requests.session()
session.proxies = {'http': '127.0.0.1:8123'}
timeout = 20
url = 'http://www.youtube.com'

html = session.get(url, timeout = timeout).text

之前一直用的好好的,找了半天也没找到原因,为什么就获取不到了
3824 次点击
所在节点    Python
11 条回复
ultimate010
2015 年 1 月 7 日
本地开的http代理能用吗?
cdwyd
2015 年 1 月 7 日
@ultimate010
能用,访问别的都是正常的
Septembers
2015 年 1 月 7 日
ultimate010
2015 年 1 月 7 日
你把youtube.com改成其他网站,试一试,如果可以,就是你的代理不能访问youtube.com
iewgnaw
2015 年 1 月 7 日
错误信息都不贴出来吗
binux
2015 年 1 月 7 日
什么叫:无法获取?获取不到?
cdwyd
2015 年 1 月 7 日
@binux
运行后没反应,一段时间后提示timeout
Sylv
2015 年 1 月 7 日
>>> import requests
>>> r = requests.get('http://www.youtube.com')
>>> r.url
u'https://www.youtube.com/'
>>> r.history
[<Response [301]>]
>>> r.history[0].headers['location']
'https://www.youtube.com/'
ryd994
2015 年 1 月 7 日
@cdwyd timeout这是典型被墙啊
yegle
2015 年 1 月 7 日
因为你设置的是HTTP的代理服务器,youtube首页会301跳转到HTTPS。
thinker3
2015 年 1 月 7 日
@yegle 貌似正确

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/159947

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX