如何从浏览器中筛选表单结果

发布于 2024-10-02 01:11:51 字数 290 浏览 7 评论 0原文

我有一个客户正在使用第三方网络软件。在一个屏幕上,我的客户填写了一张表格。在提交之前,他想要运行一些程序来捕获他输入的内容并将其插入到 csv 或数据库中。 CSV 或数据库部分很简单。从已经启动的浏览器获取数据,在另一个网络服务器上运行是我不知道该怎么做的部分。

如何捕获html表单的内容?我更喜欢使用 c#、vb.net、vbs 或类似的语言,但确实对任何东西都感兴趣。我也不想在客户端工作站上安装自定义软件,除了我在这里编写的屏幕抓取软件。我还希望用户填写表单,然后运行我的脚本来收集数据,而不必运行自定义浏览器实例。

谢谢!

I've have a client that is using a third party piece of web software. On 1 screen, my client fills out a form. Before submitting, he wants to run something that captures what he's entered in and inserts it into a csv or database. The CSV or database part is easy. Getting the data from a browser that is already started, running on another web server is the part I don't know how to do.

How can I capture the contents of the html form? I would prefer to use c#, vb.net, vbs or similar but really am interested in anything. I would also prefer not to install custom software on the client workstation except what screen scraping software I write here. I would also prefer for the user to fill out the form and they run my script to gather the data rather than having to run a custom browser instance.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

内心激荡 2024-10-09 01:11:51

在用户提交表单之前,数据仅存在于浏览器中。浏览器是您能够获取数据的唯一地方。

您将需要诸如浏览器帮助程序对象之类的东西,或者 FireFox 中的同等物。您还必须限制可以使用哪些浏览器,并且必须维护这个辅助工具。

您最好告诉客户“不”,或者找到更好的方法来完成他真正想要的事情(例如,第三方应用程序可能需要能够保存发送给它的内容)。

Before the user submits the form, the data only exist in the browser. The browser is the only place you'll be able to get the data from.

You'll need something like a Browser Helper Object, or the equivalent in FireFox. You'll also have to restrict which browsers can be used, and you'll have to maintain this helper tool.

You'll do better to tell the customer "no", or find a better way to do what he really wants (like, maybe the third-party application needs to be able to save what is sent to it).

画▽骨i 2024-10-09 01:11:51

如果您或您的客户不介意使用 Windows 窗体应用程序,则可以添加 WebBrowser 控件,然后将其指向第三方 Web 应用程序。然后,您可以尝试通过控件的 .Document 属性访问网页的元素(即表单字段)。虽然我不确定您是否可以访问特定的表单字段值。

编辑
我能够按照我所说的做到这一点。我创建了一个 Windows 窗体应用程序,添加了一个 Web 浏览器控件 (webBrowser1),然后将此 html 加载到其中(使用正确的 、 标签等):

<form id="form1" method="post" action="test.htm">
  <input type="text" id="testText" name="testText" />
  <br />
  <input type="submit" value="Save" />
</form>

注意:我做到了通过将其保存在 html 文件中并在我的 Form_Load 事件中使用 webBrowser1.Url = new Uri(@"c:\test.htm"); 来实现此目的。

然后,我可以通过这样做访问我在 testText 中输入的任何内容:

HtmlDocument doc = webBrowser1.Document; //Gets the html document
HtmlElement elem = doc.Body.All["testText"]; //Gets the input element
MessageBox.Show(elem.GetAttribute("value")); //Gets the value attribute

我希望这对您有帮助。

If you or your client don't mind using a windows forms application, you can add a WebBrowser control and then point it to the third-party web-app. Then, you could try to access the elements of the web page (ie. form fields) through the .Document property of the control. Though I'm not sure if you could access specific form field values or not.

Edit
I was able to do this with what I said. I created a windows forms application, added a webbrowser control (webBrowser1) and then loaded this html into it (with proper <html>, <head> tags and the like):

<form id="form1" method="post" action="test.htm">
  <input type="text" id="testText" name="testText" />
  <br />
  <input type="submit" value="Save" />
</form>

Note: I did this by saving it in an html file and using webBrowser1.Url = new Uri(@"c:\test.htm"); in my Form_Load event.

I was then able to access whatever I typed into testText by doing this:

HtmlDocument doc = webBrowser1.Document; //Gets the html document
HtmlElement elem = doc.Body.All["testText"]; //Gets the input element
MessageBox.Show(elem.GetAttribute("value")); //Gets the value attribute

I hope this helps you.

滿滿的愛 2024-10-09 01:11:51

我决定使用 javascript 并添加 IE 收藏夹或 Firefox 书签来实现此目的。它从表单中检索数据,将数据从查询字符串发送到 aspx 页面。然后,aspx 页面将数据写入数据库,并在写入成功与否时显示弹出图形。

这是脚本示例:

javascript:var oForm = document.forms[0];var name = oForm.elements["name"].value; void window.open("http://www.mydomain.com/page.aspx?data=" + name ,"_blank","resizable,height=130,width=130");

大家,感谢您的建议!

I decided to use javascript and add a IE favorite or a firefox book mark that achieves this. It retrieves the data from the form, sends the data to an aspx page from the query string. The aspx page then writes the data to the database and displays a pop-up graphic if the write was successful or not.

Here's a sample of the script:

javascript:var oForm = document.forms[0];var name = oForm.elements["name"].value; void window.open("http://www.mydomain.com/page.aspx?data=" + name ,"_blank","resizable,height=130,width=130");

Everyone, thanks for the suggestions!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文