如何使用htmlagilitypack提取博客文章图像 [英] How do I extract blog post image with htmlagilitypack
本文介绍了如何使用htmlagilitypack提取博客文章图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我可以使用htmlagilitypack从网站中提取第一张图片。但我希望能够提取博客文章功能图像。我使用的是firstOrDefault,它给了我给定网址上的第一张图片。
请帮帮我。
谢谢。
我尝试过:
我尝试过使用Linq ElementAt(1)我得到索引超出范围。为此,我知道,在指定的索引处没有图像。
Hi!
I am able to use htmlagilitypack to extract first image from a website. But I want to be able to extract blog post feature image. I am using firstOrDefault and it gives me the first image on the given url.
Please help me.
Thanks.
What I have tried:
I have tried using the Linq ElementAt(1) and i get index was out of range. For that I know, there is no image at that specified index.
推荐答案
尝试此链接...
c# - 如何使用HTML Agility Pack从网站上检索所有图像? - 堆栈溢出 [ ^ ]
它可能对你有用。
Try This Link...
c# - How can I use HTML Agility Pack to retrieve all the images from a website? - Stack Overflow[^]
It may help you.
Dim url As String =http://mashable.com/2016/05/27/cellphone-cancer-study/
'Dim web = New HtmlWeb()
'Dim document = web.Load(url)
Dim imgg = document.DocumentNode.Descendants()。Where(Function(n)n .Name =img)。FirstOrDefault()
image.ImageUrl = imgg.GetAttributeValue(src,String.Empty)
这只给我在博客上的第一张图片而不是博客文章的特征图片,当我做的事情时:
Dim imgg = document.DocumentNode.Descendants()。Where(Function(Function) n)n.Name =img)。elementAt(1)
image.ImageUrl = imgg.GetAttributeValue(src,String.Empty)
我收到错误当我试图从s废弃只有一张图片的那个。
非常感谢。
Dim url As String = "http://mashable.com/2016/05/27/cellphone-cancer-study/"
'Dim web = New HtmlWeb()
'Dim document = web.Load(url)
Dim imgg = document.DocumentNode.Descendants().Where(Function(n) n.Name = "img").FirstOrDefault()
image.ImageUrl = imgg.GetAttributeValue("src", String.Empty)
this only give me the first image on the blog instead of the feature image of the blog post and when i do something like:
Dim imgg = document.DocumentNode.Descendants().Where(Function(n) n.Name = "img").elementAt(1)
image.ImageUrl = imgg.GetAttributeValue("src", String.Empty)
I get error when i try to scrap from site that is having only one image.
Thanks very much.
这篇关于如何使用htmlagilitypack提取博客文章图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文