Identify & Extract the title/description of an Image (Data Scraping Pinterest)

后端 未结 2 964
半阙折子戏
半阙折子戏 2020-12-09 07:07

How can Javascript/jQuery be used to identify the description or title corresponding to an image on a webpage with multiple images and descriptions?

The page title c

2条回答
  •  粉色の甜心
    2020-12-09 07:41

    The best answer is: Look at how Pinterest does it.

    For jQuery, look at "closest" function.

    Here is just some quick and dirty untested code to give you a starting point for thinking about this, but this is very open ended question and the intelligence in your code can be as complex and robust or as simple as you want it to be.

    $('img').each(function() {
    
        var title = $(this).prop('alt') || $(this).prop('title') || $(this).closest('h1,h2,h3').text();
    
       // do something with title
    
    });​
    

提交回复
热议问题