Difficulty with MechanicalSoup forms

2019-08-27 04:09发布

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条回答
Emotional °昔
2楼-- · 2019-08-27 04:52

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.

查看更多
登录 后发表回答