Pourriez-vous nous fournir un lien vers le site Web?
Mise à jour: Vous ne savez pas si vous avez résolu le problème. Je viens de recevoir les travaux suivants pour moi, et je crois que cela devrait fonctionner pour vous aussi:
# -*- coding: utf-8 -*-
import mechanize
#-----------------------------------------------------------------------|
# The following fixes error "URLError: <urlopen error [Errno 8] _ssl.c:503".
# Include if necessary
import ssl
from functools import wraps
def sslwrap(func):
@wraps(func)
def bar(*args, **kw):
kw['ssl_version'] = ssl.PROTOCOL_TLSv1
return func(*args, **kw)
return bar
ssl.wrap_socket = sslwrap(ssl.wrap_socket)
# -----------------------------------------------------------------------|
URL = 'https://search.yahoo.com/'
BASE_URL = 'https://search.yahoo.com/'
# The form/controls you'd like to work on, which can be extracted from source by clicking "Inspect" on the page
FORM_HTML = """
<form method="get" name="s" id="sf" role="search" action="https://search.yahoo.com/search;_ylt=AwrBTveB2p9Wj.IAEDDqFAx." accept-charset="utf-8"><label for="yschsp" class="off-left">Search query</label><div id="sbq-wrap" class="sbq-w"><input type="text" class="sbq" id="yschsp" name="p" value="" autocomplete="off" autofocus="" tabindex="1" autocorrect="off" autocapitalize="off" style="-webkit-tap-highlight-color: transparent;"><div id="yui_3_10_0_1_1453316701540_15" class="sa-sbx-container"><div id="yui_3_10_0_1_1453316701540_18" class="sa lowlight"></div></div></div><input type="submit" class="sbb" value="Search" tabindex="2"><input type="hidden" name="fr" value="sfp"><input type="hidden" name="fr2" value=""><input type="hidden" name="iscqry" id="iscqry"></form>
"""
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open(URL)
# work on the FORM_HTML
res = mechanize._form.ParseString(FORM_HTML, BASE_URL)
# get the HTMLForm instance
br.form = res[1]
form = br.form
# -----------------------------------------------
# Refer to: http://stackoverflow.com/questions/13965285/use-mechanize-to-submit-form-without-control-name
# In case the control's name is NONE:
form.set_value('stackover', type= 'text', id='yschsp')
# -----------------------------------------------
# In case the control has name 'p', use the following to set the value:
#form['p'] = 'stackoverflow'
# submit the form
response = mechanize.urlopen(form.click())
# print the page content
print response.read()
ne peut pas, mais voici l'image du html où la balise select est [lien] (http: //imgmak.com/image/Kvf) –