0
請幫助修復腳本。如何通過腳本加載頁面?
import pprint
import requests
import bs4
topicsWatch = [
'http://forum.saransk.ru/',
'http://forum.saransk.ru/topic/194169-v-kakuiu-sportivnuiu-sektciiu-mozhno-zapisat-reben/',
]
#1
html = requests.get(topicsWatch[0])
print(topicsWatch[0], end='\n')
print(html.status_code) #OK
print(html.raise_for_status())
#2
html = requests.get(topicsWatch[1])
print(topicsWatch[1], end='\n')
print(html.status_code) #?????????????
print(html.raise_for_status())
有兩塊代碼。 「#1」和「2」。 塊「#1」將返回響應「200」 塊「#2」將返回響應「404」。
我不明白這一點。兩個頁面實際上都存在:
http://forum.saransk.ru/
http://forum.saransk.ru/topic/194169-v-kakuiu-sportivnuiu-sektciiu-mozhno-zapisat-reben/
如何在兩種情況下都這樣做,返回一個「200」?
輸出:
>>> ================================ RESTART ================================
>>>
http://forum.saransk.ru/
200
None
http://forum.saransk.ru/topic/194169-v-kakuiu-sportivnuiu-sektciiu-mozhno-zapisat-reben/
404
Traceback (most recent call last):
File "C:\VINT\OPENSERVER\OpenServer\domains\localhost\python\parse_html\5_forum_new\q.py", line 24, in <module>
print(html.raise_for_status())
File "C:\Python33\lib\site-packages\requests\models.py", line 773, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found
>>>