开发者

How does Facebook grab the text of the article when pasting the url?

Im a bit curious about this Facebook's useful functionality. When I paste a URL on the 'What's on your mind?' box, it almost perfectly gets the body of the article. How does Facebook do this?开发者_JS百科

Thanks!


It's part of how Facebook Share works.

The URL Linter is pretty helpful as well. For example, if we test it with this very question, you can scroll down and see where it's getting the data from

"Hello, Im a bit curious about this Facebook's useful functionality. When I paste a URL on the 'What's on your mind?' box, it almost perfectly gets the body of the article. How does Facebook do this?" extracted from <description> or first <p>


I can't speak for Facebook specifically, but there are entire companies dedicated to providing that kind of service. For example, Reddit recently outsourced preview generation to a 3rd party.

So, essentially, there's a certain amount of automation and a large amount of manual tweaking and configuration.

You might also look at the Readability tool, which extracts the main content of a web page - that might provide some insight into the processes involved.


You can put your own entries into the shared content, by using the things described in the OpenGraph protocol on Facebook developer website.


It basically goes to the page and begins sniffing for ID's in the HTML marked as Content or Main and probably a few other common terms people use when building a site and specifying where things like menus, content, main body, right menu, top menu, main article, etc are placed in the page when pulling it in dynamically (or non dynamically for that matter).

For example, look at the source of this page itself. You'll see an area that begins div id="content"

Bingo. That's where the facebook sniffer begins. It then grabs probably the first picture it finds within that area as well as the first bit of text in that area as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜