python利用什么写模块_使用内置Python模块填写Web表单数据

你确实想要Selenium.它模拟浏览器上的GUI交互.

在做诸如输入竞争表格数据之类的事情时,这将是最不可检测的方式.

A note about selenium: It is not a language-specific library. There are client specific bindings for each language. Most examples and how-to’s you’ll see are actually written in Java.

这是你的工作范例.包括提交按钮.

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

i = 2 # do it 2 times

while i > 0:

driver = webdriver.Firefox()

driver.get("http://www.jonessoda.com/contests/back2school")

def find_by_xpath(locator):

element = WebDriverWait(driver, 10).until(

EC.presence_of_element_located((By.XPATH, locator))

)

return element

class FormPage(object):

def fill_form(self, data):

find_by_xpath('//input[@name = "fname"]').send_keys(data['fname'])

find_by_xpath('//input[@name = "lname"]').send_keys(data['lname'])

find_by_xpath('//input[@name = "email"]').send_keys(data['email'])

find_by_xpath('//select[@name = "birthday_month"]').send_keys(data['month'])

find_by_xpath('//select[@name = "birthday_day"]').send_keys(data['day'])

find_by_xpath('//select[@name = "birthday_year"]').send_keys(data['year'])

return self # makes it so you can call .submit() after calling this function

def submit(self):

find_by_xpath('//input[@value = "Submit"]').click()

data = {

'fname': 'Sheep',

'lname': 'Test',

'email': 'jess@sheeptest.com',

'month': 'October',

'day': '29',

'year': '1920'

}

FormPage().fill_form(data).submit()

driver.quit() # closes the webbrowser

i = i - 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值