Javascript 使用JQuery刮取HTML元素

Javascript 使用JQuery刮取HTML元素,javascript,jquery,html,Javascript,Jquery,Html,我正在为Chrome开发一个小的扩展。除此之外,我想从我访问的页面中提取一些文本,并将其存储到一个变量中。我正在使用jQuery。我在其他帖子中尝试过一些解决方案,但似乎没有任何效果 <div id = "top-card" data-li-template="top_card" > <div class="profile-top-card top-card " > <div class="profile-card vcard"> &l

我正在为Chrome开发一个小的扩展。除此之外,我想从我访问的页面中提取一些文本,并将其存储到一个变量中。我正在使用jQuery。我在其他帖子中尝试过一些解决方案,但似乎没有任何效果

<div id = "top-card" data-li-template="top_card" >
<div class="profile-top-card top-card " >
    <div class="profile-card vcard">
        <div class="profile-card vcard">
            <div class="profile-card vcard">
                .....
                    <div class="profile-card vcard">
                        <div id="profile-card vcard">
                            <div data-li-template="profile-card vcard">
                                <h1>
                                    <span class="fn">
                                        <span class="full-name" dir="auto">I WANT THIS TEXT</span>
非常感谢任何我可以使用的想法或信息来源。
谢谢

您需要来自类名“全名”的数据。因此,在
jQuery

$('#personal_notes').click(function() {
    chrome.tabs.query( {active: true}, function(tabs) {
       var url = tabs[0].url;
       var notes = document.getElementById('notes').value;

       var name = $("body .full-name").text();
       //OR you can use below one also with minor change
       var name = $("body").find(".full-name").text();
此处不需要
正文
,而
全名
是一个类,因此您需要使用
全名
作为选择器

代码变为:

$('#personal_notes').click(function() {
chrome.tabs.query( {active: true}, function(tabs) {
var url = tabs[0].url;
var notes = $("#notes").val(); // Changed this as well
var name = $(".full-name").text(); // Here you should use .

谢谢你的回复,但似乎不起作用。我在导出的csv文件中得到一个空白单元格。有什么想法吗?@Vasilis你能在chrome的开发者控制台上直接访问该
全名的文本吗?是的,我能。您也可以测试它,只需访问随机LinkedIn个人资料(*),谢谢您的回复!它似乎不起作用。我导出的csv文件中有一个空单元格。
$(".full-name").text();
$('#personal_notes').click(function() {
chrome.tabs.query( {active: true}, function(tabs) {
var url = tabs[0].url;
var notes = $("#notes").val(); // Changed this as well
var name = $(".full-name").text(); // Here you should use .