如何在知道python中的Web表单id / name的情况下填写Web表单并返回数据

时间:2018-05-12 04:56:49

标签: html python-3.x web-scraping python-requests

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

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

1 个答案:

答案 0 :(得分:0)

我不确定你到底想要什么。但是,这是代码的一部分,它使用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()