RSSリーダーを作成しましたが、プレビュー画像も表示しようとしています。 は、ここで私は、画像を取得するために使用していると働いていない唯一のことは、私はtravelator.roウェブサイトのクラス「ST-ギャラリー」から画像を取得するための良好なパターンを作成する支援が必要なパターン画像を取得するための正規表現パターンを作成するのに助けが必要
if item?.content != nil {
print("works until here")
let htmlContent = item!.content as NSString
var imageSource = ""
let rangeOfString = NSMakeRange(0, htmlContent.length)
let regex = try! NSRegularExpression(pattern: "(http[^\\s]+(jpg|jpeg|png|tiff)\\b)", options: .caseInsensitive)
if htmlContent.length > 0 {
let match = regex.firstMatch(in: htmlContent as String, options: [], range: rangeOfString)
if match != nil {
let imageURL = htmlContent.substring(with: (match!.rangeAt(2))) as NSString
print(imageURL)
if NSString(string: imageURL.lowercased).range(of: "feedburner").location == NSNotFound {
imageSource = imageURL as String
}
}
}
if imageSource != "" {
cell.itemImageView.setImageWith(NSURL(string: imageSource) as URL!, placeholderImage: UIImage(named: "thumbnail"))
}else {
cell.itemImageView.image = UIImage(named: "thumbnail")
}
}
事前に感謝します。 :)
HTML解析ライブラリを使用します。 [正規表現はHTMLを解析できません。](http://stackoverflow.com/a/1732454/3141234)正規表現は正規言語のセットを認識します。 HTMLは文脈自由言語であり、チョムスキー階層の上位です。正規表現は文脈自由な言語を認識できません。 – Alexander