Загрузка...

Парс Каналов

Тема в разделе C# создана пользователем Minin_inactive4471240 30 май 2022. 151 просмотр

  1. Minin_inactive4471240
    Minin_inactive4471240 Автор темы 30 май 2022 3 5 сен 2021
    Помогите сделать так, чтобы по моему запросы парсились все каналы, который выдаёт ютуб
    Вот код:
    Код

    using Fizzler.Systems.HtmlAgilityPack;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web;
    using System.Windows.Forms;



    namespace Boil
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    public void label1_Click(object sender, EventArgs e)
    {

    }

    public void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    public void button1_Click(object sender, EventArgs e)
    {
    Start();
    }
    public void richTextBox1_TextChanged(object sender, EventArgs e)
    {

    }






    public void Start()
    {
    WebClient web = new WebClient();
    string txt = textBox1.Text;
    string[] hui = SortTextForReq(txt);
    string LoadString = "https://www.youtube.com/results?search_query=";
    for (int i = 0; i < hui.Length; i++)
    {
    LoadString += hui[i] + "+";
    }
    richTextBox1.AppendText(LoadString + " ");
    string resp = web.DownloadString(LoadString);
    File.WriteAllText("Query.html", resp, Encoding.UTF8);
    Process.Start("Query.html");



    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(resp);

    string pars = doc.DocumentNode.QuerySelector("ytd-app").InnerHtml;

    foreach (var item in doc.DocumentNode.QuerySelectorAll("a#yt-simple-endpoint style-scope yt-formatted-string.spellcheck.href")) //в этой строке пытаюсь найти каналы, но не работает
    {
    richTextBox1.AppendText(item.InnerText + " ");
    }


    }
    public static string[] SortTextForReq(string text)
    {
    string[] words = text.Split(' ');

    int counter = 0;

    //for (int i = 0; i < words.Length; i++)
    //{
    // if (words[i] != null || words[i] != "")
    // {
    // counter++;
    // }
    //}

    //string[] sortWords = new string[counter];
    //int iter = 0;

    //for (int i = 0; i < words.Length; i++)
    //{
    // if (words[i] != "")
    // {
    // sortWords[iter] = words[i];
    // iter++;
    // }
    // else
    // {
    // continue;
    // }
    //}
    return words;
    }


    }
    }





     
  2. vtlstolyarov
    vtlstolyarov 31 май 2022 474 8 янв 2022
    Потому что у тебя совершенно неправильный селектор, используй что-то типа
    ".ytd-channel-name a"
     
Загрузка...
Top