Python mechanize使用变量或提取的文本填充表单
我正在尝试使用python mechanize制作一个脚本来自动填充表单。具有根据其他因素变化的值。有没有办法让它从文件中读取?这是我的代码:Python mechanize使用变量或提取的文本填充表单,python,forms,submit,controls,mechanize,Python,Forms,Submit,Controls,Mechanize,我正在尝试使用python mechanize制作一个脚本来自动填充表单。具有根据其他因素变化的值。有没有办法让它从文件中读取?这是我的代码: 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.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']=open(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()
如果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()