Python请求无法获取网页

Python请求无法获取网页

问题描述:

我使用Python3和包requests来获取HTML数据。Python请求无法获取网页

我已经试过这条线

r = requests.get('https://github.com/timeline.json')

,这是对他们的教程中的例子,但无济于事。然而,当我运行

request = requests.get('http://www.math.ksu.edu/events/grad_conf_2013/')

它工作正常。我得到的错误,如

AttributeError: 'MockRequest' object has no attribute 'unverifiable' 
Error in sys.excepthook: 

我想到了错误有什么做的网页我试图获得的类型,因为这是工作的html页面只是基本的HTML我写的。

我对通常的请求和Python非常陌生。我也是新的*。

+0

http://*.com/questions/ 12659833/python-3-3-http-cookie-error – 2013-02-08 19:21:10

+0

看起来已经过时 – BBischof 2013-02-08 19:22:24

+1

无论如何,看起来像您的特定版本的Python中的错误,可能与'https'协议处理有关。用pythons'3.2.3'和'3.3.0'工作。 – 2013-02-08 19:24:57

作为一个小例子,这里是我在为了从一个网站的IP获取数据,在这种情况下开发的,并显示一个小工具:

# Import the requests module 
# TODO: Make sure to install it first 
import requests 

# Get the raw information from the website 
r = requests.get('http://whatismyipaddress.com') 
raw_page_source_list = r.text 
text = '' 

# Join the whole list into a single string in order 
# to simplify things 
text = text.join(raw_page_source_list) 

# Get the exact starting position of the IP address string 
ip_text_pos = text.find('IP Information') + 62 

# Now extract the IP address and store it 
ip_address = text[ip_text_pos : ip_text_pos + 12] 

# print 'Your IP address is: %s' % ip_address 
#   or, for Python 3 ...   # 
# print('Your IP address is: %s' % ip_address)