我試圖從網站上取消一些數據。 我想編寫的腳本,應該得到頁面的內容:使用Python /機械化select_form()時出錯?
http://www.atpworldtour.com/Rankings/Singles.aspx
應模擬用戶去藥谷額外積分和日期,每一個選項,模擬點擊進入,然後獲取數據應使用後後臺功能。
現在我一直在努力,只是選擇此選項用於其他常委:
<option value="101" >101-200</option>
這裏是我的(差)試圖嘗試這樣做:
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
import re
import urllib2
br = Browser();
br.open("http://www.atpworldtour.com/Rankings/Singles.aspx");
br.select_form(nr=0);
br["r"] = "101";
response = br.submit();
但它只是失敗在select_form(nr = 0)上應該選擇第一種形式。
這是Python的返回日誌:
>>> from mechanize import Browser
>>>
>>> from BeautifulSoup import BeautifulSoup
>>> import re
>>> import urllib2
>>>
>>>
>>>
>>> br = Browser();
>>> br.open("http://www.atpworldtour.com/Rankings/Singles.aspx");
<response_seek_wrapper at 0x311bb48L whose wrapped object = <closeable_response
at 0x311be88L whose fp = <socket._fileobject object at 0x0000000002C94408>>>
>>> br.select_form(nr=0);
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win-amd64\egg\mechanize\_mechanize.py", line 505, in select_
form
File "build\bdist.win-amd64\egg\mechanize\_html.py", line 546, in __getattr__
File "build\bdist.win-amd64\egg\mechanize\_html.py", line 559, in forms
File "build\bdist.win-amd64\egg\mechanize\_html.py", line 228, in forms
mechanize._html.ParseError
我找不到在機械化主頁的所有功能的適當的解釋。任何人都可以指向我一個正確的教程使用形式和機械化或幫助我在這個特定的問題?
安東尼