2016-12-21 59 views
0

我想webcrawl一個website,但是,我收到以下錯誤:錯誤機械化蟒蛇:沒有形成匹配NR 0

mechanize._mechanize.FormNotFoundError: no form matching nr 0. 

該腳本如下:

import mechanize 
br = mechanize.Browser() 
br.set_handle_robots(False) 
br.open("http://dbaasp.org/prediction") 
br.select_form(nr = 0) 

## See what is available on this web page: 
for f in br.forms(): 
    print f 

這怎麼可以改善?謝謝。

+1

你想改善什麼?您正在抓取的頁面不包含任何表單。 –

+0

由於它不是一種形式,有什麼辦法可以解決這個問題嗎? – user729470

回答

1

如果你想在你的Python腳本來處理這個錯誤,只是把嘗試/除了你的周圍循環。

try: 
    for f in br.forms(): 
     print(f) 
except mechanize._mechanize.FormNotFoundError as e: 
    print("Sorry no form found on this page", e) 
-1

您正在訪問的頁面上沒有任何html元素,但直接使用該標籤。你需要嵌套這裏面

<form> 
 
    First name:<br> 
 
    <input type="text" name="firstname"><br> 
 
    Last name:<br> 
 
    <input type="text" name="lastname"> 
 
</form>

+0

你怎麼能把它嵌入到腳本中? – user729470