"Mechanize"を使っていくつかのHTMLコードを抽出しています。しかし、私は出力されたHTMLコードに問題があります。基本的には、Mechanizeは特定の要素の中のコンテンツを '(n/a)'に置き換えているようです。Python Mechanizeファイヤーバグとは異なるHTMLコードHTMLコード
例(構造はFirebugの中に示されている)
<tr>
<td>
<img class="bullet" src="images/bulletorange.gif" alt="">
<span class="detailCaption">Video Format Mode:</span>
<span class="settingValue" id="vidSdSdiAnlgFormatSelectionMode.1.1">Auto</span>
</td>
</tr>
例(Mechanizeのにより構造出力)
<tr>
<td>
<img class='bullet' src='images/bulletorange.gif' alt='' />
<span class='detailCaption'>Video Format Mode:</span>
<span class='settingValue' id="vidSdSdiAnlgFormatSelectionMode.1.1">(n/a)</span>
</td>
</tr>
問題は、 "自動" が "(N/A)" によって置換されていることです。なぜ私は本当にわからない!
助けてください。なぜ機械化がこれをやっているのですか?それをどうやって修正することができますか?私のコードの下
...
def login_and_return_html(self, url_login, url_after_login, form_username, form_password, username, password):
"""
Description: Returns html code form a website that requires login.
Input Arguments: url_login (str)-The url where you enter the login username and password
url_after_login (str)-The url where you want to go after you login
form_username (str)-The name of the form for the username input field
form_password (str)-The name of the form for the password input field
username (str)-The actual username
password (str)- The actual password
Return or Output: Returns HTML code of the 'url_after_login' page
Modules and Classes: mechanize
ssl
"""
try: # Unabling SSL certificate validation
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError: # Legacy Python that doesn't verify HTTPS certificates by default
pass
else: # Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
br = mechanize.Browser() # Browser
br.set_handle_equiv(True) # Browser options
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
cj = mechanize.CookieJar() # Cookie Jar
br.set_cookiejar(cj)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(),
max_time=1) # Follows refresh 0 but not hangs on refresh > 0
br.open(url_login) # Login
br.select_form(nr=0)
try:
br.form[form_username] = username #Fill in the blank username form
br.form[form_password] = password #Fill in the blank password form
br.submit()
except:
control = br.form.find_control(form_username)
for item in control.items: #Dropdown menu username form
if item.name == username:
item.selected = True
br.form[form_password] = password #Fill in the blank password form
br.submit()
html = br.open(url_after_login).read()
return html
私はそれを試して、私が思い付くものを見てみましょう。ありがとう! –
あなたは正しいです。それはJavascriptの問題でした。 –