Python爬蟲--timeout設定--防止訪問時間過長造成假死
爬蟲有時候會因為爬去某些網頁速度極慢,影響效能。所有可以設定超時時間。
timeout單位秒
設定超時時間為0,使用try語句。
#coding:utf-8
**urllib2**
超時可以通過 urllib2.urlopen() 的 timeout 引數直接設定。
例如:
#coding:utf-8
import urllib2
try:
url = "http://www.baidu.com"
f = urllib2.urlopen(url, timeout=0) #timeout設定超時的時間
result = f.read()
print result
except Exception,e:
print 'a',str(e)
輸出異常:
a <urlopen error timed out>
timeout設定為一之後就能正常返回獲取的html程式碼了。
相關推薦
Python爬蟲--timeout設定--防止訪問時間過長造成假死
爬蟲有時候會因為爬去某些網頁速度極慢,影響效能。所有可以設定超時時間。 timeout單位秒 設定超時時間為0,使用try語句。 #coding:utf-8 **urllib2** 超時可以通過
Windows 8/8.1 進入歡迎&登入介面前黑屏且等待時間過長&登入假死解決方法
筆記本和公司的電腦同時出現這問題,和休眠無關 公司就算了,HDD也沒在意,筆記本SSD也黑屏等待一陣就匪夷所思了,於是找到解決方法 一、黑屏 問題:進入歡迎&登入介面前黑屏等待時間過長,會
Python爬蟲:scrapy爬蟲設定隨機訪問時間間隔
scrapy中有一個引數:DOWNLOAD_DELAY 或者 download_delay 可以設定下載延時,不過Spider類被初始化的時候就固定了,爬蟲執行過程中沒發改變。 隨機延時,可以降低被封
selenium 超時設定/等待時間過長自動停止(python)
用selenium爬網頁,很多時候頁面裡面的有用資訊其實已經載入完成了,但是由於頁面載入沒有徹底完成,下一步操作仍然不會執行,很耽誤時間。 然後很多其他文章中提到了一種方法: d.set_page_load_timeout(10)然而在我的測試下,這種方法不論是在firef
python 爬蟲數據準換時間格式
print %d time utc 數據 str pre ray color 1 timeStamp = 1381419600 2 dateArray = datetime.datetime.utcfromtimestamp(timeStamp) 3 otherSty
easyUI的treegrid新增節點(append)時間過長,設定等待(wait)遮罩效果
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
使用 export timeout = -1來免除ssh時間過長被強制下線的困擾
長時間連線ssh沒有操作,可能會被強制下線,這時候,我們使用以下命令就可以免除次困擾: export timeout = -1,便不再會被強制下線了。 有的人寫攻略說要寫入conf配置檔案裡,這樣確實不用每次登入後都敲一遍命令,但是實際企業環境中不可能讓我們隨意的去修改conf檔案,或者被防
關於.Net mvc 專案在本地vs執行響應時間過長無法訪問時,解決方法!
最近可能是剛升級了電腦使用了window10作業系統,總是遇到了一些以前沒有遇到過的事情! 今早來到公司本來準備寫bug的,但是當我開啟vs執行的時候發現今天的電腦響應的時間明顯的要比之前開啟網頁除錯的時間要長的多,到最後不但沒有開啟,而且還提示了一個這樣的問題! 如圖: 這就蛋
python某段程式碼執行時間過長,如何跳過執行下一步?
在工作中遇到過 個問題 執行一條程式碼時間過長 而且還不報錯,卡死在那。還要繼續執行下面程式碼,如何操作。 下面是個簡單的例項 pip安裝 第三方eventlet這個包 import time import eventlet#匯入eventlet這個模組 eventlet.monke
python getatime() 檢視檔案的訪問時間
import time,os def main(): file_name=r'C:\Temp\Req.xml' file_times_access=time.localtime(os.path.getatime(file_name)) year_access=fil
python 爬蟲 cookies設定,獲取登陸後介面。
前言 Cookie Cookie 是指某些網站伺服器為了辨別使用者身份和進行Session跟蹤,而儲存在使用者瀏覽器上的文字檔案,Cookie可以保持登入資訊到使用者下次與伺服器的會話。 Cookie原理 HTTP是無狀態的面向連線的協議, 為了保持連線狀態, 引入了
乾貨|Python爬蟲如何設定代理IP
在學習Python爬蟲的時候,經常會遇見所要爬取的網站採取了反爬取技術導致爬取失敗。高強度、高效率地爬取網頁資訊常常會給網站伺服器帶來巨大壓力,所以同一個IP反覆爬取同一個網頁,就很可能被封,這裡講述一個爬蟲技巧,設定**代理IP**。 配置環境 安裝requests庫 安
python爬蟲解決403禁止訪問錯誤
在python寫爬蟲的時候,html.getcode()會遇到403禁止訪問的問題,這是網站對自動化爬蟲的禁止,要解決這個問題,需要用到python的模組urllib2模組 urllib2模組是屬於一個進階的爬蟲抓取模組,有非常多的方法 比方說連線url=http://b
關於Hbase的RegionServer的GC持續時間過長解決辦法
hbase gc 持續時間 問題現象:分析原因:http://www.aboutyun.com/thread-11240-1-1.htmlhttp://blog.csdn.net/wwwxxdddx/article/details/50981089修改方法:只用原有的配置在後面增加 -XX:+
EntityFramework的多種記錄日誌方式,記錄錯誤並分析執行時間過長原因(系列4)
tab parameter height 優化 系統 環境 build ado.net 所有 Entity Framework 延伸系列目錄 今天我們來聊聊EF的日誌記錄. 一個好的數據庫操作記錄不僅僅可以幫你記錄用戶的操作, 更應該可以幫助你獲得效率低下的語句來幫你提高
SecureRandom生成隨機數超慢 導致tomcat啟動時間過長的解決辦法
tails spa centos 7 屬性 gpo org 解決辦法 hang iss 用騰訊雲的CentOS 7.2 CVM 服務器跑Tomcat時發現,Tomcat啟動的特別慢,通過查看日誌,發現時間主要花在實例化SecureRandom對象上了。 由該日誌可以看
網站響應時間過長的原因及解決方法
網站打不開 網站程序 cas ron height 出口 javascrip 運算 access 遇到過類似問題,我認為有以下幾個原因: 1、網站服務器故障維修(這種情況只能等段
服務器響應時間過長
服務器響應時間服務器網站響應時間過長的問題解決方法如下: 1、機器的配置。包括服務器端與客戶機端的硬件配置程度,同樣的網絡環境下,雙核的服務器的運算能力肯定要強一些,毫無疑問的,同樣的網絡環境下,用一臺賽揚的機器和奔四雙核處理器的電腦,打開同樣的網頁,速度,也肯定不一樣。 2、服務器軟件。軟件多少、穩定和軟件
關於心跳ajax請求pending狀態(被掛起),stalled時間過長的問題。涉及tcp連接異常。
.net section 解決 5.1 網絡問題 chrome瀏覽器 time iou 數據包 環境:景安快雲服務器(聽說很垃圾,但是公司買的,我也剛來),CentOS-6.8-x86_64,Apache,MySQL5.1,P
oracle中for update語句執行時間過長的問題
oracle執行查詢語句SELECT s.sid, s.serial# FROM v$locked_object lo, dba_objects ao, v$session s WHERE ao.object_id = lo.object_id AND lo.session_id = s.sid 查出的兩個字