2015-11-26 33 views
0

我寫了一個腳本來抓取Python27中的一些網頁數據。但是對於某些網站,腳本會卡住,似乎永遠運行。如何判斷一個python腳本在運行時正在做什麼?

腳本運行時,是否有辦法跟蹤它正在處理的內容?

我想知道它卡在什麼地方,或者實際上是在做什麼。

我是新的python。但我對Ruby on Rails更熟悉一些。所以我想像的是像在Rails中觀看控制檯,然後用'rails s'啓動後導航應用程序。

+0

http://stackoverflow.com/questions/1623039/python-debugging-tips有什麼用? – JCx

+0

'print'語句? –

回答

0

如果您正在從控制檯的Python腳本,你可以做這樣的事情

example.py

while condition: 
    print "I'm inside the while loop" 

之後,你可以運行

python example.py 

並且您必須在控制檯中看到"I'm inside the while loop",直到條件變爲false。如果你想打印varible的價值,你必須遵循以下步驟:

variable  = 45 
text_variable = "hello" 

while condition: 
    print "{0} -- {1}".format(variable,text_variable) 

然後你會在控制檯中看到

45 -- hello 
45 -- hello 
# And so on, until the condition returns false 
1

您可以設置和使用透明代理(burpsuite)並檢查腳本卡住的日誌。 因爲您正在使用請求模塊,請使用以下代碼。

http_proxy = "localhost:8080" 
https_proxy = "localhost:8080" 
proxyDict = { 
       "http" : http_proxy, 
       "https" : https_proxy 
      } 

r = requests.get(url, headers=headers, proxies=proxyDict) 
相關問題