Difficulty with MechanicalSoup forms

我是研究僧i 提交于 2019-12-11 15:58:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!