Where i can found the url of main image?
I have only a thumb of 200px
I try to modify the config thumb image.... but nothing work
Please help
Fabio
Support wrote:
The message has been truncated without any warning... Here is the end of the class:
public static string GetFirstImageUrl(string htmlContent)
{
if (string.IsNullOrEmpty(htmlContent)) return null;
HTMLDocument doc = new HTMLDocument();
IHTMLDocument2 doc2 = (doc as IHTMLDocument2);
doc2.write(htmlContent as object);
IHTMLElementCollection imgs = doc.getElementsByTagName("img");
int i = 0;
while (true)
{
IHTMLElement img = imgs.item(i);
if (img != null)
{
string ImageUrl = img.getAttribute("src") as string;
Stream str = null;
HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(ImageUrl);
HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
str = wRes.GetResponseStream();
var imageOrig = System.Drawing.Image.FromStream(str);
int height = imageOrig.Height;
int width = imageOrig.Width;
if (height > 50 && width > 50)
{
return ImageUrl;
}
else
{
i++;
continue;
}
}
else
{
break;
}
}
return null;
}
public static bool IsRilevant(SyndicationItem item)
{
return IsRilevant(item.Title) || IsRilevant(item.Summary) || IsRilevant(item.Content as TextSyndicationContent);
}
public static bool IsRilevant(TextSyndicationContent textContent)
{
if (textContent == null) return false;
else return IsRilevant(textContent.Text);
}
public static bool IsRilevant(string text)
{
if (text == null) return false;
return text.ToLower().Contains("keyword");
}
}
}
This is my class. The method you need to retrieve the image is GetFirstImageUrl(string)
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RSSImporter.Model;
using System.ServiceModel.Syndication;
using System.Xml;
using mshtml;
using System.Net;
using System.Drawing;
using System.IO;
namespace RSSImporter
{
public class Importer
{
private SharedLibrary.ILogger Logger
{
get { return SharedLibrary.LoggerManager.GetLogger(RSSImporter); }
}
public void ReadAll()
{
int siteCounter = 0;
int totalArticleCounter = 0;
foreach (RSSProvider site in DBContext.RSSProviders)
{
try
{
XmlReader reader = XmlReader.Create(site.RssUrl);
SyndicationFeed feed = SyndicationFeed.Load(reader);
Logger.Info(string.Format("Start reading feed {0}.", site.Name));
int articleCounter = 0;
foreach (SyndicationItem item in feed.Items)
{
if (!site.Hidden && (site.DontFilter || IsRilevant(item)))
{
string url = item.Links.First().Uri.AbsoluteUri;
// Look if I've already downloaded it before...
FeedArticle news = site.FeedArticles.SingleOrDefault(no => no.Url.Equals(url));
// ... If Not
if (news == null)
{
articleCounter++;
totalArticleCounter++;
news = new FeedArticle();
news.Site = site;
news.Title = item.Title.Text;
news.DateTime = item.PublishDate.DateTime;
news.Text = item.Summary.Text;
news.Url = url;
var textContent = (item.Content as TextSyndicationContent);
if (textContent != null)
{
news.ImageUrl = GetFirstImageUrl(textContent.Text);
}
site.FeedArticles.Add(news);
}
}
}
Logger.Info(string.Format("End reading feed {0}. Imported {1} new articles", site.Name, articleCounter));
siteCounter++;
}
catch (Exception ex)
{
Logger.ErrorException(string.Format("Error reading feed {0}.", site.Name), ex);
}
}
DBContext.SaveChanges();
Logger.Info(string.Format("End feed reading process. Read {0} articles from {1} feeds.", totalArticleCounter, siteCounter));
}
public static string GetFirstImageUrl(string htmlContent)
{
if (string.IsNullOrEmpty(htmlContent)) return null;
HTMLDocument doc = new HTMLDocument();
IHTMLDocument2 doc2 = (doc as IHTMLDocument2);
doc2.write(htmlContent as object);
IHTMLElementCollection imgs = doc.getElementsByTagName("img");
int i = 0;
while (true)
{
IHTMLElement img = imgs.item(i);
if (img != null)
{
string ImageUrl = img.getAttribute("src") as string;
Stream str = null;
HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(ImageUrl);
HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
str
P.S. Yes I want to automatically search for new articles from a pre-filled list of rss feed.
Don't you know there are already classes for parsing rss built in .NET framework? You have just to reference System.ServiceModel assembly.
Some time ago I developed an analog procedure for another application, but I'm not able to do it for NopCommerce.
For images I made a method that inspect the html of the article body and finds the first img tag that contains a useful image.
If you wish I can post the class responsible for reading rss feeds.
Hi I don't understand what do you mean.
What I need to do is find a way for read external rss and automatic create new Noparticle and put its in a particular category
tell me if you can make it in nop article or like you tell me a month ago create a new module that make this
thanks a lot for your support
Fabio