HTML表单自动填充程序

时间:2018-06-19 09:05:05

标签: javascript php web automation cross-domain

我有一个我大学生的数据库。我想使用这些数据填写http://www.rmlau.site/urn_r/Registration.aspx

上的录取表格

我试图使用JavaScript,但由于XSS而无法运行。

我有没有办法实现同样的目标?

我可以在任何平台(Windows / Linux / Web Based)上使用解决方案。

2 个答案:

答案 0 :(得分:1)

我知道这是JavaScript的问题,但是“有没有办法可以实现相同的目标?”促使我回答这个问题。您可以使用自动填写表格。

这是一个有效的脚本,用于在 Python 中使用Selenium填写表单。希望这对您有所帮助。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time


driver = webdriver.Chrome()
driver.get("http://www.rmlau.site/urn_r/Registration.aspx")

# Students information, loading from excel, csv whatsoever
name = "John Doe"
moName = "Jane"
faName = "Doe Doe"
dob = "17071997"
email = "foo@foo.com"
mobileNo = "090078601"
adharNo = "1231"
course = 'B.Sc. Part One'



time.sleep(3)

# Fill Form
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtName").send_keys(name)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtMotherName").send_keys(moName)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtFatherName").send_keys(faName)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtEmail").send_keys(email)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtMobilNo").send_keys(mobileNo)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtAdhar").send_keys(adharNo)
select = Select(driver.find_element_by_id('ctl00_ContentPlaceHolder1_ddl_course'))
select.select_by_visible_text(course)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtDOB").send_keys(dob)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtDOB").clear()
driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtDOB").send_keys(dob)


# Submit
driver.find_element_by_id("ctl00_ContentPlaceHolder1_btnsave").click()

答案 1 :(得分:0)

基于Web的解决方案 首先输入唯一列(在这种情况下为手机号码)以从数据库中搜索。使用ajax调用。然后通过id方法使用javascript填写所有字段

$(document).ready(function(){

   $("#search").keyup(function(){
  if($("#search").val().length>=10){ 

  $.ajax({
   type: "post",

   url: '<?php echo base_url(); ?>search',

   cache: false,    

   data:'search='+$("#search").val(),

   success: function(response){  

    document.getElementById("name").value = response[0].name;

    document.getElementById("age").value = response[0].age;

    }
   },
   error: function(){      
    alert('Error while request..');
   }
  });
  }
  return false;
   });
 });