English 中文(简体)
需要帮助XPATH 特定Html img tag[封闭式]的弧度值
原标题:Need help with XPATH for src value of a specific Html img tag [closed]
Closed. This question needs details or clarity. It is not currently accepting answers.

我对《人权行动计划》略感新,理解大多数基本内容,但我对某个具体问题感到有些麻烦。

I am attempting to parse a Motley Fool page and return the source of the image for the caps score of a stock.

For example: if you look at the source for the page: http://caps.fool.com/Ticker/SLT.aspx I want the source for http://g.foolcdn.com/art/ratings/stars/trans/5stars-trans-lg.png

我只想到的是,如果可能的话,那是 follows。

I am currently working with:

xpath = "//div[@class= subtle marginT ]"

然而,这并没有恢复。 我知道,它可能要求很多,但如果你感到要回答的话,我也非常赞赏迅速提出答案,因为我想要学习亚太伙伴关系,而不只是让这个问题发挥作用。

最佳回答

Based on your URL this worked for me:

var imageNode = doc.DocumentNode.SelectSingleNode("//table[@id= tickerStats ]/tbody/tr/td/img");
string imageText = imageNode.Attributes["src"].Value;

Basically just grabbing the closest element that has an id, then walking the tree down to where you want to be.

或者,这也会奏效,似乎不太清洁(因为只要只有一个形象,你就没有真正地关注桌面上的多功能结构):

var statsNode = doc.DocumentNode.SelectSingleNode("//table[@id= tickerStats ]");
var imageNode = statsNode.SelectSingleNode(".//img");
string imageText = imageNode.Attributes["src"].Value;
问题回答

Use:

//table[@id= tickerStats ]/tbody/tr/td/img/@src

This selects any attribute named src of any element named img that is a child of a td that is a child of a tr that is a child of a tbody that is a child of any table in the document, that has an id attribute with value tickerStats .

www.un.org/Depts/DGACM/index_spanish.htm 如果你只需要这一属性(假定以上XPath的表述选择了单一属性术语),则使用:

string(//table[@id= tickerStats ]/tbody/tr/td/img/@src)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签