gpt4 book ai didi

javascript - 使用 jQuery 从特定的 中提取文本

转载 作者:行者123 更新时间:2023-11-30 10:42:50 24 4
gpt4 key购买 nike

我在外部页面上运行 AJAX 查询,并试图只返回 County 的数据。我当前的脚本是从所有表格单元格中提取文本,但我无法在我的生活中让它简单地提取县名。

当前正在运行的脚本:

$( ".zipCode" ).each(function( intIndex ){
var zipCodeID = $(this).attr('id');
console.log('http://www.uscounties.org/cffiles_web/counties/zip_res.cfm?zip='+zipCodeID);
$.ajax({
url: 'http://www.uscounties.org/cffiles_web/counties/zip_res.cfm?zip='+zipCodeID,
type: 'GET',
success: function(res) {
var headline = $(res.responseText).find("p").text();
console.log(headline);
$('#'+zipCodeID).empty();
$('#'+zipCodeID).append(headline);
}
});
});

正在查询的页面示例: http://www.uscounties.org/cffiles_web/counties/zip_res.cfm?zip=56159

这应该适用于所有输入的 ZIPS。页面布局是一样的,我只是无法获得只返回县的功能。任何帮助或建议都会很棒。谢谢!

最佳答案

由于该页面上完全没有 idclass,您实际上没有太多可做的。如果您可以访问该页面的源代码,请将 idclass 粘贴到单元格上,让您的生活变得更加轻松。如果没有,您将不得不使用您对页面结构的了解来查找县。像这样的东西将专门用于您链接到的那一页。如果其他页面有轻微的变化,这将失败:

var headline = $(res.responseText).find("table > tr:eq(2) > td:eq(3)").text();

假设页面上只有一个表格,并且县始终位于第二行的第三个单元格中。

关于javascript - 使用 jQuery 从特定的 <td> 中提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10130906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com