简体   繁体   English

是否可以在网页上获取所有链接的列表?

[英]Is it possible to get a list of all links with a class on a webpage?

There are a lot of links on a webpage. 网页上有很多链接。

The ones I want to make a list of (there will always be exactly 22) all have the same class 那些我想拍的列表(总是会有正好 22)都具有相同的类

"name notranslate": “名称未翻译”:

在此输入图像描述

Is it possible to get a list of all the links with that class? 是否有可能获得该类所有链接的列表? Or at least everything after the "Href" 或者至少在“Href”之后的一切

This program is written in C#. 该程序是用C#编写的。

I tried a for loop with web.Document.GetElementByID (web is the name of the webBrowser control) but that just did nothing. 我尝试使用web.Document.GetElementByID(web是webBrowser控件的名称)的for循环,但这没有做任何事情。

You can use HtmlAgilityPack 您可以使用HtmlAgilityPack

var web = new HtmlAgilityPack.HtmlWeb();
var doc = web.Load(url);
var list = doc.DocumentNode.SelectNodes("//a[@class='name notranslate']")
               .Select(a => a.Attributes["href"].Value)
               .ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM