判断页面访问情况(通用前置代码)
本文最后更新于 211 天前,其中的信息可能已经有所发展或是发生改变。

import requests
from requests.exceptions import ReadTimeout, ConnectionError, RequestException

try:
   req = requests.get('http://www.thelon.cm/xxx.htm',timeout=5)      # url, 使用request获取相应数据
   
   print(req.status_code)
except ReadTimeout:
  # 超时异常
  print('Timeout')
  # 需要把当前的url放到任务中,过一段时间再尝试连接
except ConnectionError:
  # 连接异常
  print('Connection error')
except RequestException:
  # 请求异常
  print('Error')
else:
  if req.status_code==200:
     print('访问正常!')
     #将爬取的网页req.text保存在本地
     
     fb=open("t.html","wb")    
     fb.write(req.content)
     fb.close()
  if req.status_code==404:
     print('页面不存在!')
     #把当前的url从爬虫任务中删除掉
  if req.status_code==403:
     print('页面禁止访问!')
  #...
判断页面访问情况(通用前置代码) : http://116.62.240.154:9520/fangwengyn/
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇