我正在尝试创建一个简单的RSS Feed网站 我可以通过这样做获得一些RSS提要:
> F0822 14:32:49.065506 29630 server.go:101] Unable to create proxer:
> failed to initialize iptables: error creating chain
> "KUBE-PORTALS-CONTAINER": exit status 3: iptables v1.4.21: can't
> initialize iptables table `nat': Table does not exist (do you need to
> insmod?) Perhaps iptables or your kernel needs to be upgraded.
大多数RSS Feed的标题和链接工作,但图像和描述没有 由于很多rss费用的图像都是html里面的描述,如下所示:
let article = {
'title': item.title,
'image': item.image.url,
'link': item.link,
'description': item.description,
}
如何从中获取图片的网址?
编辑:
{ title: 'The Rio Olympics Are Where TV Finally Sees the Future',
description: '<div class="rss_thumbnail"><img src="http://www.wired.com/wp-content/uploads/2016/08/GettyImages-587338962-660x435.jpg" alt="The Rio Olympics Are Where TV Finally Sees the Future" /></div>Time was, watching the Olympics just meant turning on your TV. That\'s changed—and there\'s no going back. The post <a href="http://www.wired.com/2016/08/rio-olympics-tv-finally-sees-future/">The Rio Olympics Are Where TV Finally Sees the Future</a> appeared first on <a href="http://www.wired.com">WIRED</a>.',...
这是我的一些代码,基本上我正在尝试从有线rss获取图像网址 如果我使用'image':item.image.url,它就不起作用。那我应该把它改成什么呢?
答案 0 :(得分:1)
使用xml2js将xml转换为json
*((char *)pNode + 16)
答案 1 :(得分:0)
答案 2 :(得分:0)
一个想法是使用正则表达式。例如:
var re = /(src=)(\\'htt.*\\')/g
var img_string = "your image tag string"
var match = re.exec(img_string)
var result = match[1]
答案 3 :(得分:-1)
您可以使用DOMDocument解析器来获取Image源。
$html = "<img title=\'A San Bernardino County Fire Department firefighter watches a helitanker make a water drop on a wildfire, seen from Cajon Boulevard in Devore, Calif., Thursday, Aug. 18, 2016. (David Pardo/The Daily Press via AP)\' height=\'259\' alt=\'APTOPIX California Wildfires\' width=\'460\' src=\'http://i.cbc.ca/1.3730399.1471835992!/cpImage/httpImage/image.jpg_gen/derivatives/16x9_460/aptopix-california-wildfires.jpg\' />";
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$src = $xpath->evaluate("string(//img/@src)"); # "/images/image.jpg"