Попытка выбрать элемент Javascript с помощью модуля Python Spynner.
(ПРИМЕЧАНИЕ: имя пользователя и пароль не реальны)
Вот список, из которого я пытаюсь получить его:
<tr>
<td valign="middle" align="right">
<select onkeypress="javascript:if ( event.keyCode == 13 ){valid();}" style="font-family:Tahoma; font-size:11px;FONT-WEIGHT :normal;height:20px;" name="mkt">
<option value="0">All Markets</option>
<option value="IBESLA~AR">Argentina </option>
<option value="IBESAA~AU">Australia </option>
<option value="IBESEA~AT">Austria </option>
<option value="IBESEB~BE">Belgium </option>
<option value="IBESLB~BR">Brazil </option>
<option value="IBESNC~CA">Canada </option>
<option value="IBESLC~CL">Chile </option>
<option value="IBESFC~CN">China </option>
<option value="IBESLL~CO">Colombia </option>
<option value="IBESDC~HR">Croatia </option>
<option value="IBESEC~CZ">Czech Republic </option>
<option value="IBESSD~DK">Denmark </option>
<option value="IBESKE~EG">Egypt </option>
<option value="IBESDE~EE">Estonia </option>
<option value="IBESSF~FI">Finland </option>
<option value="IBESEF~FR">France </option>
<option value="IBESED~DE">Germany </option>
<option value="IBESEH~GR">Greece </option>
<option value="IBESFH~HK">Hong Kong </option>
<option value="IBESEM~HU">Hungary </option>
<option value="IBESFI~IN">India </option>
<option value="IBESFL~ID">Indonesia </option>
<option value="IBESEZ~IE">Ireland </option>
<option value="IBESFZ~IL">Israel </option>
<option value="IBESEI~IT">Italy </option>
<option value="IBESFJ~JP">Japan </option>
<option value="IBESFR~JO">Jordan </option>
<option value="IBESFM~MY">Malaysia </option>
<option value="IBESKP~MU">Mauritius </option>
<option value="IBESLM~MX">Mexico </option>
<option value="IBESKM~MA">Morocco </option>
<option value="IBESEN~NL">Netherlands </option>
<option value="IBESAN~NZ">New Zealand </option>
<option value="IBESSN~NO">Norway </option>
<option value="IBESFQ~PK">Pakistan </option>
<option value="IBESLP~PE">Peru </option>
<option value="IBESFP~PH">Philippines </option>
<option value="IBESEG~PL">Poland </option>
<option value="IBESEP~PT">Portugal </option>
<option value="IBESEK~RO">Romania </option>
<option value="IBESER~RU">Russia </option>
<option value="IBESFS~SG">Singapore </option>
<option value="IBESDR~SK">Slovakia </option>
<option value="IBESDV~SI">Slovenia </option>
<option value="IBESKS~ZA">South Africa </option>
<option value="IBESFK~KR">South Korea </option>
<option value="IBESEE~ES">Spain </option>
<option value="IBESBL~LK">Sri Lanka </option>
<option value="IBESSS~SE">Sweden </option>
<option value="IBESES~CH">Switzerland </option>
<option value="IBESFA~TW">Taiwan </option>
<option value="IBESFT~TH">Thailand </option>
<option value="IBESET~TR">Turkey </option>
<option value="IBESEX~GB">United Kingdom </option>
<option value="IBESNA~US">United States </option>
</select>
</td>
<td valign="middle">
<img width="5px" src="images/spacer.gif">
</td>
<td valign="middle">
<a href="javascript:setChildFrameWidth();valid()">
</td>
<td valign="middle">
<img width="10px" src="images/spacer.gif">
</td>
</tr>
А вот мой код:
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
import re
import spynner
from BeautifulSoup import BeautifulSoup
import time
br = spynner.Browser()
br.create_webview()
br.show()
br.set_html_parser(BeautifulSoup)
br.load("https://www.thomsononeim.com/s-log_in.asp")
br.fill("input[name=txtLoginID]", "USERNAME")
br.fill("input[name=txtPWD]", "PASSWORD")
br.click("input[name=Submit]", wait_load=True)
br.click("input[name=Market]", wait_load=True)
br.select("IBESNA~US")
br.browse()
br.close()
Что я делаю не так с выбором?Это дает мне ошибку:
Traceback (most recent call last):
File "C:\Python27\Sample Programs\Spynner Basic.py", line 17, in <module>
br.select("IBESNA~US")
File "C:\Python27\lib\site-packages\spynner\browser.py", line 862, in select
self._runjs_on_jquery("select", jscode)
File "C:\Python27\lib\site-packages\spynner\browser.py", line 394, in _runjs_on_jquery
raise SpynnerJavascriptError("error on %s: %s" % (name, code))
SpynnerJavascriptError: error on select: jq('IBESNA~US').attr('selected', 'selected')