Python 机械化以用变量或提取的文本填充表单
Python mechanize to fill form with variables or extracted text
我正在尝试用 python 制作一个脚本来自动填写表格。具有根据其他因素而变化的值。有没有办法让它从文件中读取?这是我的代码:
br.open('https://url/url)
br.select_form(nr=0)
br.form['xxxxx']='123456'
br.form['yyyyy']='7890'
br.submit()
print br.response().read()
我怎样才能得到类似的东西
br.form['xxxx']=打开(xxx.txt,r)
所以它从 xxx.txt 读取并填写表格。似乎无法在网上找到任何东西...
br.form['xxxx']=open(xxx.txt,r).read()
这将直接给出文件的内容。
如果 txt 文件只有一行,试试这个。
br.open(url)
br.select_form(nr=0)
with open('example.txt', 'r') as f:
for line in f:
br.form['xxxxx']= line
br.form['yyyyy']='7890'
response = br.submit()
search = response.read()
另一方面:
br.open(url)
br.select_form(nr=0)
lines = [line.rstrip('\n') for line in open('example.txt')]
br.form['xxxxx']= lines[0]
br.form['yyyyy']= lines[1]
response = br.submit()
search = response.read()
我正在尝试用 python 制作一个脚本来自动填写表格。具有根据其他因素而变化的值。有没有办法让它从文件中读取?这是我的代码:
br.open('https://url/url)
br.select_form(nr=0)
br.form['xxxxx']='123456'
br.form['yyyyy']='7890'
br.submit()
print br.response().read()
我怎样才能得到类似的东西
br.form['xxxx']=打开(xxx.txt,r)
所以它从 xxx.txt 读取并填写表格。似乎无法在网上找到任何东西...
br.form['xxxx']=open(xxx.txt,r).read()
这将直接给出文件的内容。
如果 txt 文件只有一行,试试这个。
br.open(url)
br.select_form(nr=0)
with open('example.txt', 'r') as f:
for line in f:
br.form['xxxxx']= line
br.form['yyyyy']='7890'
response = br.submit()
search = response.read()
另一方面:
br.open(url)
br.select_form(nr=0)
lines = [line.rstrip('\n') for line in open('example.txt')]
br.form['xxxxx']= lines[0]
br.form['yyyyy']= lines[1]
response = br.submit()
search = response.read()