Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mechanize使用变量或提取的文本填充表单_Python_Forms_Submit_Controls_Mechanize - Fatal编程技术网

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()

我正在尝试使用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.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()