简体   繁体   English

使用servlet从外部页面获取数据

[英]Get data from external page using servlets

I'm doing my first college HTML project wich I need to get data from an external Webpage using servlets. 我正在做我的第一个大学HTML项目,这需要使用servlet从外部网页获取数据。

First, on the website, I need to enter a key code and fill one captcha to get to the page I need. 首先,在网站上,我需要输入一个密钥代码并填写一个验证码才能进入所需的页面。 I'm leaving the captcha to the user, planning to load the page on a div or iframe, and when the user hit Next, I'll hide it and process the data using the servlets. 我将验证码留给用户,计划将页面加载到div或iframe上,当用户单击“下一步”时,我将其隐藏并使用servlet处理数据。

The page is: http://www.nfe.fazenda.gov.br/portal/consulta.aspx?tipoConsulta=completa&tipoConteudo=XbSeqxE8pl8= 该页面是: http : //www.nfe.fazenda.gov.br/portal/consulta.aspx?tipoConsulta=completa&tipoConteudo=XbSeqxE8pl8=

I'm using: 我正在使用:

<iframe id="iframeSEFAZ" src="http://www.nfe.fazenda.gov.br/portal/consulta.aspx?tipoConsulta=completa&tipoConteudo=XbSeqxE8pl8=#ctl00_ContentPlaceHolder1_pnlInformacoesConsulta"></iframe>

After I fill the data, I'm able to see the data I want. 填写数据后,我可以查看所需的数据。 But I wonder how do I transfer (buffer?) my current page (the iframe after I fill the captcha) to the servlet. 但是我不知道如何将当前页面(填充验证码后的iframe)传输(缓冲?)到servlet。

I already have the method to parse the page: 我已经有解析页面的方法:

public void parse_pagina (String pagina) {
DataBaseColetor db = new DataBaseColetor ();
db.openConnectionDB();

try {
  Document doc = Jsoup.parse (pagina); 

  String texto_html = doc.html ();
  System.out.println ("\n\n Página coletada: \n\n " + texto_html);


  Elements div = doc.select ("[id=\"divImpressao\"]"); //Seleciona o elemento com id = "divImpressao".

  this.armazenarElemento (db, "div", "conteudo", "", "", div); 

} catch (Exception e) {
  e.printStackTrace ();
}

} }

I'm new to web development, so all the help is much appreciated. 我是Web开发的新手,因此非常感谢所有帮助。 And sorry for my bad english. 对不起,我的英语不好。

Store the value which you want to share across pages, in a session attribute for the first time. 第一次在会话属性中存储要在页面之间共享的值。

Access it in any page with the session. 在会话的任何页面中访问它。

Eg. 例如。 sessionObj.setAttribute("sharedVariable","abc"); sessionObj.setAttribute(“ sharedVariable”,“ abc”); // at the page where your element comes first //在您的元素排在第一的页面

Then wherever you want this data. 然后,在任何需要此数据的地方。 Use the session attribute name. 使用会话属性名称。

Eg. 例如。 String s = (String) sessionObj.getAttribute("sharedVariable"); 字符串s =(字符串)sessionObj.getAttribute(“ sharedVariable”);

After searching around I learned that cross site contents like my iframe can not be read by javascript. 搜寻之后,我得知javascript无法读取跨站内容,例如iframe。 So I'm doing this server side. 因此,我正在此服务器端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM