我是python的新手(过去做了一些java).我最近决定自动化一个过程,每年花费我大约20个小时.我需要使用他们拥有的登录表单登录供应商的网站.然后加载一个新表单,我可以从中选择一个订单,然后它加载另一个表单,我可以提交一个项目编号.然后,这会加载包含商品大小和每个尺寸价格的页面,我会将此信息放入电子表格中.该行具有基于大小数量的列,然后是价格(item,sm,med,lg,9.99,10.99,12.99).在返回浏览器之后,我点击后退按钮并将下一个项目编号加载到字段中,依此类推.我将以你的方式发送大量信息,对此感到抱歉.
在进行一些研究后,我发现了一个名为mechanize的Python库,它似乎可以很容易地提交Web表单然后收集数据.
'''
Created on Sep 29, 2012
@author: Teddy
'''
from tkinter import *
import mechanize
import urllib
import logging
import sys
import http.cookiejar
def main():
br = mechanize.Browser()
cj = http.cookiejar.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.open('https://*******/cgi-bin/wfos/order.exe')
# Select the login form named "login"
br.select_form(name="login")
# User credentials, this is usrname and passwords to submit to form
br.form['custno'] = '*******'
br.form['Password1'] = '*******'
br.form['Password2'] = '**********'
# Login, submits to the form
br.submit()
main()
Run Code Online (Sandbox Code Playgroud)
目前,当我编译这个时,我收到一个错误: …
我有一个类分配来使用Scanner读取数据.
import java.util.Scanner;
public class Project23
{
public static void main(String[] args)
{
// Declarations and instantiations.
Scanner scan = new Scanner(System.in);
String any = "";
boolean more = false;
double purchase = 0.0;
// Ask if user would like to run program?
System.out.print("Do you have any purchases? Y/N?: ");
// Ready value into string.
any = scan.nextLine();
System.out.println();
// If any is equal to y or Y it will set the value of more to true
// this runs …Run Code Online (Sandbox Code Playgroud)