Comments (4)
The parser doesn't currently detect images within feed items. This is planned for the future though.
The best thing to do now is to use an NSScanner and scan the content/summary of the feed item and look for "<img" and then "src=", and scan the image url that way.
from mwfeedparser.
Yes I use this code to get the first image but it doesn't work fine... For example It can't retrieve the 1st image in this code:
[p] [p][img class="aligncenter size-full wp-image-21789" title="mac-app-store_t" src="http://static.slidetomac.com/wp-content/uploads/2011/07/mac-app-store_t.jpg" alt="" width="507" height="300" /][/p] [p][span id="more-21780"][/span][/p] [p]Solo qualche giorno fa Apple....
NOTE: To show you the code I have replaced < and > with [ and ]
My function is:
-
(NSString *)getFirstImage:(NSString *)htmlString{
NSString *urlImage=nil;
NSScanner *theScanner = [NSScanner scannerWithString:htmlString];
// find start of IMG tag
[theScanner scanUpToString:@"<img" intoString:nil];
do {
[theScanner scanUpToString:@"src" intoString:nil];
NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@""'"];
[theScanner scanUpToCharactersFromSet:charset intoString:nil];
[theScanner scanCharactersFromSet:charset intoString:nil];
[theScanner scanUpToCharactersFromSet:charset intoString:&urlImage];if( [urlImage rangeOfString:@"feedads.g.doubleclick.net"].location == NSNotFound ) return urlImage;
}while (![theScanner isAtEnd]);
if([theScanner isAtEnd] ) return nil;
else return urlImage;
}
What's wrong in my code?
from mwfeedparser.
I can't see anything wrong with the code at a quick glance. You should use the debugging features in Xcode to step through and see what's going on with your code. Then you'll be able to see what's happening.
Another note, you should probably set the scanner to not skip any whitespace characters (set charactersToBeSkipped to nil), and also I'd scan for " src=" instead of just "src", it's safer.
Best of luck with figuring it out.
from mwfeedparser.
I have made this feather that is getting the first image in the item.
I made my modification Below:
MWFeedItem.h
NSData* firstImg;
@Property (nonatomic, retain) NSData* firstImg;
MWFeedItem.m
add synthesize and dealoc
RootViewController.m
- (NSString *)getFirstImage:(NSString *)htmlString{
NSScanner *theScanner;
NSString *text = nil;
theScanner = [NSScanner scannerWithString: htmlString];
// find start of tag
[theScanner scanUpToString: @"<img src=\"" intoString: NULL];
if ([theScanner isAtEnd] == NO) {
NSInteger newLoc = [theScanner scanLocation] + 10;
[theScanner setScanLocation: newLoc];
// find end of tag
[theScanner scanUpToString: @"\"" intoString: &text];
}
return text;
}
-
(void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);NSString* str_imageUrl = [self getFirstImage:item.summary];
item.firstImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:str_imageUrl]];
if (item) [parsedItems addObject:item];
}
Hope can help...
from mwfeedparser.
Related Issues (20)
- Why Weird Licence
- Enclosures does not contain all media content HOT 3
- Retrieving <wfw:commentRss> and <slash:comments>
- Can`t call delegate functions
- iOS 9 SSL Issues HOT 3
- How To parse Image (media:content) HOT 1
- How display image for different RSSfedd's Key. like (media:content , image, thumbnail)
- Problem with & HOT 1
- Atom parsing: MWFeedItem 'link' is null HOT 1
- Search with keyword.
- Impliment search option.
- Problem (and solution) handling 32bit unicode entities
- Current code is not working HOT 5
- exc_bad_access when dismissing MWFeedParser delegate
- create app with wordpress
- Support for IOS10?
- Error Domain=MWFeedParser Code=2 "A server with the specified hostname could not be found." UserInfo={NSLocalizedDescription=A server with the specified hostname could not be found.}
- Error parsing img tag (and possibly dates)
- Crash On iOS 8 / Xcode 6 - Beta 6
- Using MWFeedParser for parsing only HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mwfeedparser.