问题
First, I am French so if there are mistakes in my english I'm sorry. So here is my problem, I have hard time with mechanicalsoup. So here is my HTML page:
<form class="XFYOY" method="post"><h2 class="vvzhL ">Inscrivez-vous pour voir les photos et vidéos de vos amis.</h2>
Here are just the first line. I want to create an automatic form but there is not action and I don't know what to put in browser.select_form():
browser.select_form('form[action=/post]')
browser["emailOrPhone"] = "0689754327"
browser["fullName"] = "Jean"
What I put is not working because the form I have don't have a action. What can I do ?
Thx, Lazare
回答1:
Even though your form does not have an action
, it has a uniquely identifiable attribute in class="XDYOY"
. Therefore, you can select it with the .XFYOY
CSS selector:
import mechanicalsoup
browser = mechanicalsoup.StatefulBrowser()
browser.open(WEBSITE_URL)
browser.select_form(".XFYOY")
browser["emailOrPhone"] = "0689754327"
browser["fullName"] = "Jean"
browser.submit_selected()
You can find a list of other selectors on W3 Schools.
来源:https://stackoverflow.com/questions/50664029/difficulty-with-mechanicalsoup-forms