2013-02-08 52 views
2

我使用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非常陌生。我也是新的stackoverflow。

+0

http://stackoverflow.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

回答

0

作爲一個小例子,這裏是我在爲了從一個網站的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)