Selenium Web 抓取 C# 尝试返回一个值

问题描述 投票:0回答:1

我尝试从名为 Bidding Ends 的字段返回日期和时间值: 我尝试过其他代码组合,但似乎无法弄清楚

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace WebScraperDemo
{
    class Program
    {
        static void Main(string[] args)
        {
         IWebDriver driver = new ChromeDriver();
         driver.Navigate().GoToUrl("https://www.bidrl.com/auction/autotool-auction-1525-c-street-marysville-ca-september-19th-134834/item/wheel-cover-17686623/");

            //this line works
            String text1 = driver.FindElement(By.CssSelector("span[ng-bind-html='item.title']")).Text;
            System.Diagnostics.Debug.WriteLine(text1);

            //dont work
            String text2 = driver.FindElement(By.CssSelector("li[ng-if='item.end_time']")).Text;
         System.Diagnostics.Debug.WriteLine(text2);

        }
    }
}
c# selenium-webdriver web screen-scraping
1个回答
0
投票
li[ng-if='item.end_time']

上面的 CSS 选择器不正确,它没有定位页面上的任何元素。

如果以下是您要提取的内容?

然后尝试以下代码:

String text2 = driver.FindElement(By.XPath("//b[text()='Bidding Ends:']//following-sibling::div")).Text;
© www.soinside.com 2019 - 2024. All rights reserved.