首页 > 解决方案 > 如何在 python 中知道 Web 表单 ID/名称,填写 Web 表单并返回数据

问题描述

我目前正在尝试将信息自动提交到该网站上的网络表单中:https ://coinomi.com/recovery-phrase-tool.html不幸的是我不知道表单的名称,似乎无法从中找到源代码。现在我尝试使用 requests python 模块填写表单,并且在抓取之前通过 URL 传递参数。不幸的是,我找不到表格的名称,所以我不能这样做。

如果可能的话,我想在https://github.com/Coinomi/bip39/blob/master/bip39-standalone.html使用网站的离线版本来做到这一点,这样它更安全,但我几乎不知道如何使用常规使用我拥有的工具创建 Web 表单,更不用说从我的计算机本地访问了。

标签: htmlpython-3.xweb-scrapingpython-requests

解决方案


我不确定您到底在寻找什么。但是,这是代码的一部分,selenium用于填写您提到的表单的某些部分。

import selenium
from selenium import webdriver
from selenium.webdriver.support.select import Select

browser = browser = webdriver.Chrome('C:\\Users...\\chromedriver.exe')

browser.get('https://coinomi.com/recovery-phrase-tool.html')

# Example to fill a text box 
recoveryPhrase = browser.find_element_by_id('phrase')
recoveryPhrase.send_keys('your answer')

# Example to select a element 
numberOfWords = Select(browser.find_element_by_id('strength'))
numberOfWords.select_by_visible_text('24')


# Example to click a button
generateRandomMnemonic = browser.find_element_by_xpath('/html/body/div[1]/div[1]/div/form/div[4]/div/div/span/button')
generateRandomMnemonic.click()

推荐阅读