我基本上需要在this site课堂上向所有朋友发送推荐请求。这就是页面的样子(登录后):
我需要逐个输入文本框中的卷号,我想通过脚本自动执行所有卷号的循环。卷号的形式为10 / CSE / XX,其中XX在范围内(1,92)。我该怎么做? 这是html源代码中的特定部分。
<div class="row">
<div class="span9">
<h2>Request New Testimonial</h2>
<form name="request" action="requesttestimonial.php" method="POST">
<input type="text" name="requestroll" placeholder="Roll number of the person you want to request a testimonial" />
<input type="submit" value="Send Request" name="submitrequest" />
</form>
</div>
</div>
登录页面:
<form class="navbar-form pull-right" method="POST" action="login.php">
<input class="span2" name="rollnumber" type="text" placeholder="Roll Number">
<input class="span2" name="password" type="password" placeholder="Password">
<button type="submit" class="btn" name="signin">Sign in</button>
</form>
任何语言都可以。
答案 0 :(得分:1)
您可以使用Java的Selenium软件包。它很简单并且支持各种各样的HTML控件,除非你正在寻找特定于python的东西,在这种情况下忽略我的答案
编辑:
package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example {
public static void main(String[] args) {
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
取自http://code.google.com/p/selenium/wiki/GettingStarted的示例,这足以满足您的需求
答案 1 :(得分:-1)
我使用python中的twill,这使得工作比我想象的更简单,这是代码:
from twill.commands import go, fv, submit
go('http://lcnitd.com/yearbook/2014/index.php')
fv("2","rollnumber","10/CSE/2")
fv("2","password","myPassword")
submit('0')
go('http://www.lcnitd.com/yearbook/2014/request.php')
n=1
roll="10/CSE/"
while(n<100):
sleep(2)
temp=roll+`n`
print n
fv("2","requestroll",temp)
n+=1
submit('0')
showforms()
可用于查看网页上的表单,formclear()
可用于清除表单。