从选项/选择网络表单下载数据

发布于 2024-10-02 05:26:39 字数 1141 浏览 0 评论 0原文

假设有一个网站,有一系列分层的选项/选择下拉菜单。当用户从下拉列表 A 中进行选择时,其选择的值将发布到服务器并填充下拉列表 B。下拉菜单 B 以相同的方式填充下拉菜单 C。当选择下拉菜单 C 时,将显示特定于他们在 C 中选择的数据。以前的选择会一直保留,除非他们更改了更高的内容,在这种情况下,所有内容都会重置为低于该值。在 HTML 中,它看起来像这样:

Drop-Down A 
<select class="submitOnChange">
 <option value="a1">A</option>
 <option value="a2" SELECTED>B</option>
 <option value="a3">C</option>
</select>
Drop-Down B
<select class="submitOnChange">
 <option value="b1" SELECTED>B-A</option>
 <option value="b2">B-B</option>
 <option value="b3">B-C</option>
</select>
Drop-Down C
<select class="submitOnChange">
 <option value="c1">B-A-A</option>
 <option value="c2">B-A-B</option>
 <option value="c3" SELECTED>B-A-C</option>
</select>
[Data for B-A-C is shown here because they clicked that]

该脚本的具体工作方式是,每次选择更改时都会向自身发送所有选定选项的 POST。

我想从这个网络应用程序下载所有数据;也就是说,我想查看与所有可能的下拉 C 值相关的数据。最好的方法是什么?我看到 wget 设置为递归地使用链接,但似乎不适用于这样的表单。我对最简单、最快的方法感兴趣。我了解 PHP,所以我愿意在 cURL 中编写脚本,但是如果有一个更简单的解决方案,例如已经可以完成此操作的程序(wget?),我会很感兴趣。欢迎任何提示或建议。

Suppose there is a website that has a hierarchical series of option/select drop-downs. When the user makes a selection from drop-down A, the value of their selections is posted to the server and drop-down B is populated. Drop-down B populates drop-down C in the same fashion. When drop-down C is selected, data is shown particular to their selection in C. Previous selections are preserved along the way, unless they change something higher up in which case everything is reset below that. In HTML it looks like this:

Drop-Down A 
<select class="submitOnChange">
 <option value="a1">A</option>
 <option value="a2" SELECTED>B</option>
 <option value="a3">C</option>
</select>
Drop-Down B
<select class="submitOnChange">
 <option value="b1" SELECTED>B-A</option>
 <option value="b2">B-B</option>
 <option value="b3">B-C</option>
</select>
Drop-Down C
<select class="submitOnChange">
 <option value="c1">B-A-A</option>
 <option value="c2">B-A-B</option>
 <option value="c3" SELECTED>B-A-C</option>
</select>
[Data for B-A-C is shown here because they clicked that]

The script works specifically by sending a POST of all the selected options to itself every time a select changes.

I would like to download all of the data from this web application; that is to say I would like to see the data associated with all possible drop-down C values. What would be the best way to do that? I see that wget is setup to work recursively with links, but seemingly not with forms like this. I'd be interested in the simplest and fastest way for doing this. I know PHP so I'd be open to writing up a script in cURL, however if there's a simpler solution such as a program out there that does this simply already (wget?) I'd be interested. Any tips or suggestions welcome.

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

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

发布评论

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

评论(3

御弟哥哥 2024-10-09 05:26:39

您可以使用 CURL 来做到这一点。

您可以从命令行使用它:

curl -d "name=Rafael%20Sagula&phone=3320780"                 http://www.where.com/guest.cgi

来源是 CURL 手册:http://curl.haxx.se /docs/manual.html

You may use CURL to do that.

You can use it from command line :

curl -d "name=Rafael%20Sagula&phone=3320780"                 http://www.where.com/guest.cgi

Source is the CURL manual : http://curl.haxx.se/docs/manual.html

只怪假的太真实 2024-10-09 05:26:39

您可以拥有类似于链接列表的信息结构,其中包含数据和父主键。这样您就可以一次性下载所有数据(例如 JSON)。

我们所做的是设置三个 Web 方法,第一个提供所有设置 A 选项,第二个和第三个采用一个和两个参数,所有三个方法都向客户端提供 JSON,由 JQuery 和 ajax 调用使用:

var responseObject = {};
responseObject.parameterA = $('#selectA option:selected').val();
responseObject.parameterB = $('#selectB option:selected').val();
responseObject.parameterC = $('#selectC option:selected').val();
var jsonResult = JSON.stringify(responseObject);

$.ajax({
    type: "POST",
    url: "http://whereever.com",
    data: jsonResult,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (j) { 
        var options = '';
        for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].value + '">' + j[i].text + '</option>';
}

在本例中,成功函数填充下一个选择,但您可以按照您希望的方式重新格式化数据。 J 包含数据。

You could have information structured like a linked list, where you have the data, and the parent primary key. That way you could download all the data in one shot as JSON for example.

What we did was setup three web methods, the first offering all set A options, the second and third taking one and two parameters, all three offering JSON down to the client, consumed with JQuery and an ajax call:

var responseObject = {};
responseObject.parameterA = $('#selectA option:selected').val();
responseObject.parameterB = $('#selectB option:selected').val();
responseObject.parameterC = $('#selectC option:selected').val();
var jsonResult = JSON.stringify(responseObject);

$.ajax({
    type: "POST",
    url: "http://whereever.com",
    data: jsonResult,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (j) { 
        var options = '';
        for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].value + '">' + j[i].text + '</option>';
}

In this case, the success function populates the next select, but you could reformat the data in anyway you wish. J contains the data.

游魂 2024-10-09 05:26:39

babonk,

我认为你无法使用该 html 文件将数据发布到服务器,因为你错过了选择部分中的“name”属性,它们应该如下所示:

Drop-Down A 
<select class="submitOnChange" name="selectA">
 <option value="a1">A</option>
 <option value="a2" SELECTED>B</option>
 <option value="a3">C</option>
</select>
Drop-Down B
<select class="submitOnChange" name="selectB">
 <option value="b1" SELECTED>B-A</option>
 <option value="b2">B-B</option>
 <option value="b3">B-C</option>
</select>
Drop-Down C
<select class="submitOnChange" name="selectA">
 <option value="c1">B-A-A</option>
 <option value="c2">B-A-B</option>
 <option value="c3" SELECTED>B-A-C</option>
</select>

然后你可以使用以下内容获取内容以下 wget 命令列表:

wget -O yourhtml.htm --post-data "selectA=a1&selectB=b1&selectC=c1" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b1&selectC=c2" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b1&selectC=c3" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b2&selectC=c1" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b2&selectC=c2" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b2&selectC=c3" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b3&selectC=c1" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b3&selectC=c2" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b3&selectC=c3" http://yoururl.com/
......
wget -O yourhtml.htm --post-data "selectA=a3&selectB=b3&selectC=c3" http://yoururl.com/

babonk,

I think you couldn't post the data to your server with that html file, because you've missed the "name" attribute in the select section, they should be like the following:

Drop-Down A 
<select class="submitOnChange" name="selectA">
 <option value="a1">A</option>
 <option value="a2" SELECTED>B</option>
 <option value="a3">C</option>
</select>
Drop-Down B
<select class="submitOnChange" name="selectB">
 <option value="b1" SELECTED>B-A</option>
 <option value="b2">B-B</option>
 <option value="b3">B-C</option>
</select>
Drop-Down C
<select class="submitOnChange" name="selectA">
 <option value="c1">B-A-A</option>
 <option value="c2">B-A-B</option>
 <option value="c3" SELECTED>B-A-C</option>
</select>

And then you could get the content with the following wget commands list:

wget -O yourhtml.htm --post-data "selectA=a1&selectB=b1&selectC=c1" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b1&selectC=c2" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b1&selectC=c3" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b2&selectC=c1" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b2&selectC=c2" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b2&selectC=c3" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b3&selectC=c1" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b3&selectC=c2" http://yoururl.com/
wget -O yourhtml.htm --post-data "selectA=a1&selectB=b3&selectC=c3" http://yoururl.com/
......
wget -O yourhtml.htm --post-data "selectA=a3&selectB=b3&selectC=c3" http://yoururl.com/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文