0

I'm developing a small extension for Chrome. Among others, I want to scrape some text from the page I visit and store it to a variable. I am using jQuery. I have tried some solutions from other posts, but nothing seems to work.

<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>

My code so far is:

$('#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();

Any ideas or sources of info that I could use, are much appreciated. Thank you

2 Answers 2

1

You need data from class name "full-name". So you should use . just before class name as a class selector in 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();
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply, but it doesn't seem to work. I get a blank cell to my exported csv file. Any thoughts why?
@Vasilis Can you directly access text of that full-name in developer console of chrome?
Yes I can. You can test it too, just visit a random LinkedIn profile (linkedin.com/profile/view?id=*)
1
$(".full-name").text();

No need of body here and full-name is a class so you need to use .full-name as the selector.

The code becomes:

$('#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 .

1 Comment

Thanks for your reply! It doesn't seem to work. I'm getting an empty cell on my exported csv file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.