[英]Scrape HTML element with JQuery
我正在为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>
到目前为止,我的代码是:
$('#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").find("full-name").text();
非常感谢我可以使用的任何想法或信息来源。 谢谢
您需要来自类名“全名”的数据。 因此,您应该使用.
就在将类名作为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();
$(".full-name").text();
这里不需要body
, full-name
是一个类,因此您需要使用.full-name
作为选择器。
代码变为:
$('#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 .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.