我正在处理InstaPaper应用程序接口
我使用这个字符串来提取文章的内容。
$Bookmark_Text = $connection->getBookmarkText($Bookmark['bookmark_id']);不幸的是,它拉动了整个HTML,基本上把html结构放到了我的HTML中。
举例说明。
<html>
<head></head>
<body>
<html>
<head>Instapaper Title</head>
<body>InstaPaper Article Content</body>
</html>
</body>
</html>关于如何获取"Instapaper文章内容“有什么想法吗?
谢谢!
发布于 2012-08-27 23:45:49
下面是一些JS代码,它只提取文章并删除Instapaper的内容(例如,顶部和底部栏)。
html.replace(/^[\s\S]*<div id="story">|<\/div>[^<]*<div class="bar bottom">[\s\S]*$/gim, '');
请注意,它可能会随着Instapaper的HTML输出的变化而变化。
发布于 2012-05-19 08:27:05
使用解析器提取<body>的内容。PHP has some built in,但是有一些others可能更容易使用。
如果$Bookmark_Text是一个有效的超文本标记语言文档,就应该这样做。
$dom = new DOMDocument();
$dom->loadHTML($Bookmark_Text);
$body = $dom->getElementsByTagName('body')->item(0);
$content = $body->ownerDocument->saveHTML($body);https://stackoverflow.com/questions/10661247
复制相似问题