Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.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脚本_Python_User Interface_Automated Tests_Urllib - Fatal编程技术网

自动在网站中输入一些文本并获取其源代码的python脚本

自动在网站中输入一些文本并获取其源代码的python脚本,python,user-interface,automated-tests,urllib,Python,User Interface,Automated Tests,Urllib,我正在使用Python进行生物医学命名提取 现在我必须交叉检查输入文本的结果,并解析提交文本后得到的HTML文本的源代码 我想在我的GUI中做同样的事情,也就是说,我从GUI中输入并将文本提交到这个网站,然后获取源代码,这样我就不必每次都通过浏览器进行交叉检查 提前谢谢事实上,这是一个很好的问题 你要做的第一件事就是浏览一下网站的源代码。 如果你查看网站的源代码,你会看到这段代码 <form method="POST" action="a.cgi"> <p> Please

我正在使用Python进行生物医学命名提取

现在我必须交叉检查输入文本的结果,并解析提交文本后得到的HTML文本的源代码

我想在我的GUI中做同样的事情,也就是说,我从GUI中输入并将文本提交到这个网站,然后获取源代码,这样我就不必每次都通过浏览器进行交叉检查


提前谢谢

事实上,这是一个很好的问题

你要做的第一件事就是浏览一下网站的源代码。 如果你查看网站的源代码,你会看到这段代码

<form method="POST" action="a.cgi">
<p>
Please enter a text that you want to analyze.
</p>
<p>
<textarea name="paragraph" rows="15" cols="80" wrap="soft">
... some text here ...
### This is a sample. Replace this with your own text.

</textarea>
</p>
<p>
<input type="submit" value="Submit Text" />
<input type="reset" />
</p>
</form>
我们要发送的数据将被发送到与此地址连接的地址

http://text0.mib.man.ac.uk/software/geniatagger/a.cgi
但是我们要送什么到那里呢? 我们需要一个数据,数据作为“段落”POST参数发送,您可以看到,由于表单具有带有值POST的属性方法,textarea的名称是“段落”

我们使用这个python代码打开它

import urllib
import urllib2

text =  """
        Further, while specific constitutive binding to the peri-kappa B site is seen in monocytes, stimulation with phorbol esters induces additional, specific binding. Understanding the monocyte-specific function of the peri-kappa B factor may ultimately provide insight into the different role monocytes and T-cells play in HIV pathogenesis. 

### This is a sample. Replace this with your own text.
        """
data = {
        "paragraph" : text 
       }

encoded_data = urllib.urlencode(data)
content = urllib2.urlopen("http://text0.mib.man.ac.uk/software/geniatagger/a.cgi",
        encoded_data)
print content.readlines()
到目前为止我们得到了什么?我们为您的GUI程序提供了一个“引擎”。 您可以做的是使用python解析这个内容变量(可选) 您提到要在GUI中显示它?
您可以使用GTK或Qt来实现这一点,并将此功能映射到单个按钮,您必须阅读a,实现此目的非常简单。如果你有问题,请评论这篇文章,我可以用GUI扩展这个答案

非常感谢@jan Vorcak你能解释一下为什么你把数据作为字典以及关于urllib.urlencode的更多信息吗我已经用python gtk制作了GUI谢谢你的关注你能给我一些链接吗我把数据当作字典,因为它需要urllib.urlencode方法,它返回附加到urlopen方法的编码的_数据,这导致将其作为POST请求发送,我认为所有这些都可以在
import urllib
import urllib2

text =  """
        Further, while specific constitutive binding to the peri-kappa B site is seen in monocytes, stimulation with phorbol esters induces additional, specific binding. Understanding the monocyte-specific function of the peri-kappa B factor may ultimately provide insight into the different role monocytes and T-cells play in HIV pathogenesis. 

### This is a sample. Replace this with your own text.
        """
data = {
        "paragraph" : text 
       }

encoded_data = urllib.urlencode(data)
content = urllib2.urlopen("http://text0.mib.man.ac.uk/software/geniatagger/a.cgi",
        encoded_data)
print content.readlines()