python使用mechanize与网页交互

import sys,time
import getpass
import mechanize, json, urllib
      
username = getpass.getuser()
password = ""
                    
url='https://**/controller.pl'
br = mechanize.Browser()
br.open(url)
br.select_form("query")
br["user"] = username
br["pass"] = password
br.submit()

def chkcorr(region):
    time.sleep(0.5)

    pcontent = open(pfile).readlines()
    pcontent = map(lambda s:s.strip(), pcontent)
    pcontent = "\n".join(pcontent)

    para = {"action":"pair_corr", "region":region.upper(), "percent":count}

    data = urllib.urlencode(para)
    response = br.open(url, data).read()
    response = json.loads(response)
    return response   

你可能感兴趣的:(Python)