Page 11 of 23 FirstFirst ... 91011121321 ... LastLast
Results 101 to 110 of 222

Thread: Notes tests, Scrapping, YouTube

  1. #101
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10

    Popuar Videos Playlist

    Page 11 https://excelfox.com/forum/showthrea...YouTube/page11




    Some note in support of this main forum post
    https://eileenslounge.com/viewtopic....303644#p303644

    Post 19753 #101
    https://excelfox.com/forum/showthrea...g/page11#19753
    https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping/page11#19753









    Popular videos So geht YouTube
    https://www.youtube.com/@SogehtYouTu...t=p&shelf_id=0
    https://www.youtube.com/playlist?lis...-GN0JHdtoul_9A


    Unlisted
    So geht YouTube
    https://www.youtube.com/@SogehtYouTube
    1 / 667 Play all


    https://www.youtube.com/watch?v=l8TY...-GN0JHdtoul_9A
    https://www.youtube.com/watch?v=l8TY...oul_9A&index=1
    https://www.youtube.com/watch?v=h15o...ul_9A&index=76
    https://www.youtube.com/watch?v=cYJx...l_9A&index=151
    https://www.youtube.com/watch?v=dcQN...l_9A&index=226
    https://www.youtube.com/watch?v=FDg3...l_9A&index=301
    https://www.youtube.com/watch?v=t_Xu...l_9A&index=376
    https://www.youtube.com/watch?v=5Dkj...l_9A&index=451
    https://www.youtube.com/watch?v=1tT7...l_9A&index=526
    https://www.youtube.com/watch?v=g9kO...l_9A&index=601

    https://www.youtube.com/watch?v=l8TYMHlqlLM&list=UULPwInqvNXb-GN0JHdtoul_9A
    https://www.youtube.com/watch?v=l8TYMHlqlLM&list=UULPwInqvNXb-GN0JHdtoul_9A&index=1
    https://www.youtube.com/watch?v=h15o6YLzfqc&list=UULPwInqvNXb-GN0JHdtoul_9A&index=76
    https://www.youtube.com/watch?v=cYJxctyMO2s&list=UULPwInqvNXb-GN0JHdtoul_9A&index=151
    https://www.youtube.com/watch?v=dcQNQP9i_WE&list=UULPwInqvNXb-GN0JHdtoul_9A&index=226
    https://www.youtube.com/watch?v=FDg34qCE8-Y&list=UULPwInqvNXb-GN0JHdtoul_9A&index=301
    https://www.youtube.com/watch?v=t_Xuqu6Rw2Q&list=UULPwInqvNXb-GN0JHdtoul_9A&index=376
    https://www.youtube.com/watch?v=5DkjHTTqIPc&list=UULPwInqvNXb-GN0JHdtoul_9A&index=451
    https://www.youtube.com/watch?v=1tT7m5qAR4o&list=UULPwInqvNXb-GN0JHdtoul_9A&index=526
    https://www.youtube.com/watch?v=g9kOyaXsJlk&list=UULPwInqvNXb-GN0JHdtoul_9A&index=601
    Last edited by DocAElstein; 02-25-2023 at 02:50 PM.

  2. #102
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10
    This post , #102 19741
    https://excelfox.com/forum/showthrea...ge11#post19741
    https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube/page11#post19741

    https://excelfox.com/forum/showthrea...ll=1#post19741
    https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube?p=19741&viewfull=1#post19741





    Second attempt

    Previously, and in my first attempt ( https://eileenslounge.com/viewtopic....303644#p303644 https://excelfox.com/forum/showthrea...YouTube/page10 ) I looked at all Videos from channel So geht YouTube ( https://www.youtube.com/@SogehtYouTube )
    In thus second attempt I will look at another play list from the same channel, Popular videos
    I do note the number of videos is exactly the same as in Videos, so they may be the same … we will see.
    ( Some of this will be repeated text from the first attempt, with bits added. All a bit mixed up, but it’s just my own rough notes for later reference )…….
    The previous story… ……….( https://excelfox.com/forum/showthrea...ll=1#post19701 ) ……………….
    _ In the long play list I looked at it seems you only get a text file of all the stuff I want for a bit more than 75 videos at a time. This makes sense and ties up with the experience when you view manually in real time: The scroll box only goes up to on average a bit over the first 75.


    Scrapping that, or rather to say, playing around with the text file from the page source text from this
    Code:
     https://www.youtube.com/watch?v=rM-CtC6cklI&list=UULFwInqvNXb-GN0JHdtoul_9A    '  --  main play list link
    ,give links of this form
    https://http://www.youtube.com/watch?v=rM-Ct...oul_9A&index=1
    https://http://www.youtube.com/watch?v=YsnmN...oul_9A&index=2
    https://http://www.youtube.com/watch?v=KIx_8...oul_9A&index=3

    …….. up to about &index=79
    If you want the next chunk of videos, and a new text file of it all, you have to click on a video towards the bottom. ( https://i.postimg.cc/65L3ydNF/Click-...t-next-lot.jpg ) I thought I would keep stuff in some organized order, so tried getting all the text in a text file from these 9 links, the ones ending with &index=1, &index=76, &index=151, &index=226 …. 301, 376,451,526,601
    That sort of worked…. Eventually…
    _ I end up with 9 big text files to play with So that is sort of Part 1. I got now all the info I need, somewhere I expect, in those files… https://i.postimg.cc/R06JWCxf/9-Big-...text-files.jpg


    _ a small snag: Previously using the main link, https://http://www.youtube.com/watch?v=rM-Ct...-GN0JHdtoul_9A , gets the first 79 links and with the index number, which is not essential but useful to have. But use a link with the extra &index=123 and I can’t find or get the index number from those 9 text files. Could be hidden there somewhere. I can’t see it initially. Maybe later.
    No matter, not so important
    _ ( I am actually using initially a hybrid Yasser/ SpeakEasy suggestion code to get those. So
    Object "MSXML2.ServerXMLHTTP"
    and the
    .setRequestHeader "User-Agent", "Chrome".
    Maybe that’s a sort of “belt and braces” approach? I don’t know. I have not had the time to look in great detail at the differences yet in the three files. The hybrid comes out the smallest of the three.
    ( https://i.postimg.cc/MK5Q4rYc/Hybrid...-text-file.jpg ) )
    …………………………

    The new second story:
    I will loop this time all 9 links to get the text files, instead of re hard coding 9 times as I did the last time, ( but I will run the macro from the VB Editor in step F8 mode as usual initially. )

    Here the files:

    Coding to get those 9 text files
    Code:
    Sub WieGehtsYouTubeURLServerChromeHybridStep75_2()   '     https://eileenslounge.com/viewtopic.php?p=303644#p303644   https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube/page11#post19741  https://excelfox.com/forum/showthread.php/2656-Automated-Search-Results-Returning-Nothing            https://excelfox.com/forum/showthread.php/973-Lookup-First-URL-From-Google-Search-Result-Using-VBA
     On Error GoTo Bed
        '_1 First section get the long text string of the HTML coding of the internet Page
        '_1(i) get the long single text string
    Dim strURLs As String: Let strURLs = "https://www.youtube.com/watch?v=l8TYMHlqlLM&list=UULPwInqvNXb-GN0JHdtoul_9A&index=1" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=h15o6YLzfqc&list=UULPwInqvNXb-GN0JHdtoul_9A&index=76" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=cYJxctyMO2s&list=UULPwInqvNXb-GN0JHdtoul_9A&index=151" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=dcQNQP9i_WE&list=UULPwInqvNXb-GN0JHdtoul_9A&index=226" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=FDg34qCE8-Y&list=UULPwInqvNXb-GN0JHdtoul_9A&index=301" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=t_Xuqu6Rw2Q&list=UULPwInqvNXb-GN0JHdtoul_9A&index=376" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=5DkjHTTqIPc&list=UULPwInqvNXb-GN0JHdtoul_9A&index=451" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=1tT7m5qAR4o&list=UULPwInqvNXb-GN0JHdtoul_9A&index=526" & vbCr & vbLf & _
    "https://www.youtube.com/watch?v=g9kOyaXsJlk&list=UULPwInqvNXb-GN0JHdtoul_9A&index=601"
    Dim URLs() As String: Let URLs() = Split(strURLs, vbCr & vbLf, 9, vbBinaryCompare)
    Dim Cnt As Long
        For Cnt = LBound(URLs()) To UBound(URLs())
        Dim strURL As String, Indx As String
         Let strURL = URLs(Cnt)
         Let Indx = Right(strURL, Len(strURL) - InStrRev(strURL, "&", -1, vbBinaryCompare))
         Let Indx = Replace(Indx, "=", "_", 1, 1, vbBinaryCompare)
                With CreateObject("MSXML2.ServerXMLHTTP")
                 .Open "GET", strURL, False ' '
                 '.Open "GET", "", False ' '
                 'No extra info here for type GET
                 '.setRequestHeader bstrheader:="Ploppy", bstrvalue:="PooH" ' YOU MAY NEED TO TAKE OUT THIS LINE
                                                                                            '.setRequestHeader bstrheader:="If-Modified-Since", bstrvalue:="Sat, 1 Jan 2000 00:00:00 GMT" '  https://www.autohotkey.com/boards/viewtopic.php?t=9554  ---   It will caching the contents of the URL page. Which means if you request the same URL more than once, you always get the same responseText even the website changes text every time. This line is a workaround : Set cache related headers.
                 .setRequestHeader "User-Agent", "Chrome"  '  https://eileenslounge.com/viewtopic.php?p=303639#p303639
                 .send ' varBody:= ' No extra info for type GET. .send actually makes the request
                    While .readyState <> 4: DoEvents: Wend ' Allow other processes to run while the web page loads. Think this is part of the True option
                Dim PageSrc As String: Let PageSrc = .responseText ' Save the HTML code in the (Global) variable. ': Range("P1").Value = PageSrc 'For me for a print out copy to text file etc.    The responseText property returns the information requested by the Open method as a text string
                End With
            '_1(ii)  Optional secion  to put the text string into a text file , for ease of code developments
            Dim FileNum2 As Long: Let FileNum2 = FreeFile(0)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
            Dim PathAndFileName2 As String
             Let PathAndFileName2 = ThisWorkbook.Path & "\" & "SecondAttemptPopular\" & "WieGehtsYouTubePopularServerChrome" & Indx & ".txt" ' "WieGehtsYouTubeServerChrome526" & ".txt" ' "WieGehtsYouTubeServerChrome451" & ".txt" '  "WieGehtsYouTubeServerChrome376" & ".txt" '  "WieGehtsYouTubeServerChrome301" & ".txt" '  "WieGehtsYouTubeServerChrome226" & ".txt" '  "WieGehtsYouTubeServerChrome151" & ".txt" '  "WieGehtsYouTubeServerChrome76" & ".txt"   '   "WieGehtsYouTubeServerChrome1" & ".txt"   '
            Open PathAndFileName2 For Output As #FileNum2 ' ' The text file will be made if not there, and if it is there and already contains data, then the data will be overwritten
             Print #FileNum2, PageSrc '
             Close #FileNum2
        Next Cnt
    Exit Sub  '  Normal code error in the case of no errors
    Bed:
     MsgBox prompt:=Err.Number & ":  " & Err.Description: Debug.Print Err.Number & ":  " & Err.Description
    End Sub   ' Code end in the case of any error
    '    Dim sTitle As String
    '     Let sTitle = Split(Split(PageSrc, """title"":{""runs"":[{""text"":""")(1), """}]}")(0)
    '
    '    Dim sViews As String
    '     Let sViews = Split(Split(PageSrc, """shortViewCount"":{""simpleText"":""")(1), """}}}")(0)
    
    Last edited by DocAElstein; 02-19-2023 at 02:26 AM.

  3. #103
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10

    Post 103 #post19742
    https://excelfox.com/forum/showthrea...ge11#post19742
    https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube/page11#post19742






    Part2
    So I have the 9 text files, and similarly to the first attempt, ( https://excelfox.com/forum/showthrea...ll=1#post19711 ) and I will advance the coding a bit to loop all the text files.

    So, as before I decide to get out all 11 digit unique YouTube bits ( like WDCmlmylNm8 ) you have in a typical YouTube video link, like https://www.youtube.com/watch?v=WDCmlmylNm8 .
    I find by inspection that there seems to be all these 11 digit unique YouTube bits, (sometimes duplicated**) in some text ending with like hqdefault.jpg. So that is what is looked for, then a bit of text manipulation is done to pick out the 11 digit unique YouTube bit
    The macro will, as before, check for duplicates of that 11 digit bit in each text file**, but there may be duplicates for the list from each text file as I click a bit above the last link, say on 76th link ,rather than the typical last 79th link, ( if I clicked on the 79th link I would get the unique 11 digit bit for the 79th video twice from the first two text files, by clicking on the 76th link I will get in both the first two text files the 11 digit bit for the 76th 77th 78th and 79th ) (Edit Note: I noticed later that because of the looping in Sub GetPlayListLinksFromTextFileUsinghqdefaultjpg_Popu larPlayList() results in the first few duplicates not being added. )
    Here the macro:

    As I am advancing the coding with looping, I will go straight into the final output worksheet, in this case worksheet ElevenDigitYT(2) , (and as Edit noted, all final duplicates are automatically removed)

    Here the macro:
    Code:
    
    '   https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube/page11#post19742
    Sub GetPlayListLinksFromTextFileUsinghqdefaultjpg_PopularPlayList()  '   look for this - hqdefault.jpg
    Rem 0a
    Dim WsPop As Worksheet:  Set WsPop = ThisWorkbook.Worksheets.Item("ElevenDigitYT(2)")
    'Set Ws1 = ThisWorkbook.Worksheets.Item("RoughNotes")
    Rem 0b An Array of all the 9 text files got from the last macro   Sub WieGehtsYouTubeURLServerChromeHybridStep75_2()
    Dim strTxts As String: Let strTxts = "WieGehtsYouTubePopularServerChromeindex_1.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_76.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_151.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_226.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_301.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_376.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_451.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_526.txt" & vbCr & vbLf & _
    "WieGehtsYouTubePopularServerChromeindex_601.txt"
    Dim Txts() As String: Let Txts() = Split(strTxts, vbCr & vbLf, 9, vbBinaryCompare)
        
    Dim Cnt As Long
        For Cnt = LBound(Txts()) To UBound(Txts())    ' Loop all the text files got from the last macro   Sub WieGehtsYouTubeURLServerChromeHybridStep75_2() ==
        ' Rem 1 Get the text files as a long single string
        Dim FileNum As Long: Let FileNum = FreeFile(1)                                    ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
        Dim PathAndFileName As String, TotalFile As String
         '                                             Let PathAndFileName = ThisWorkbook.Path & Application.PathSeparator & "WieGehtsYouTubeServerChrome.txt"   '
         Let PathAndFileName = ThisWorkbook.Path & Application.PathSeparator & "SecondAttemptPopular\" & Txts(Cnt)   ' "WieGehtsYouTubeServerChrome601.txt" ' "WieGehtsYouTubeServerChrome526.txt" ' "WieGehtsYouTubeServerChrome451.txt" ' "WieGehtsYouTubeServerChrome376.txt" ' "WieGehtsYouTubeServerChrome301.txt" ' "WieGehtsYouTubeServerChrome226.txt" ' "WieGehtsYouTubeServerChrome151.txt" '  "WieGehtsYouTubeServerChrome76.txt" '  '"WieGehtsYouTubeServerChrome1.txt"   '
        Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundamental type data input...
        ' Let TotalFile = Space(LOF(FileNum)) '....and wot receives it has to be a string of exactly the right length
        'Get #FileNum, , TotalFile
        '  Or  http://www.eileenslounge.com/viewtopic.php?p=295782&sid=f6dcab07c4d24e00e697fe4343dc7392#p295782
         Let TotalFile = Input(LOF(FileNum), FileNum)
        Close #FileNum
        ' Rem 2 Get all links based on the unique bit of index=x, where x is 1 2 3 4 ...... etc
        '                   Dim Cnt As Long: Let Cnt = 1
        Dim TextBit As String: Let TextBit = TotalFile
        Dim posJpg As Long: Let posJpg = InStr(1, TextBit, "hqdefault.jpg", vbBinaryCompare)
            Do While posJpg <> 0
            Dim strURL As String: Let strURL = Mid(TextBit, posJpg - 12, 11)
            Dim Unics As String
                If InStr(1, Unics, strURL, vbBinaryCompare) = 0 Then
                 Let Unics = Unics & " " & strURL
                 Dim Lr1 As Long: Let Lr1 = WsPop.Range("A" & WsPop.Rows.Count & "").End(xlUp).Row
                 Dim Nr As Long
    '                If WsPop.Range("B1").Value = "" Then
    '                 Let Nr = 1
    '                Else
                     Let Nr = Lr1 + 1
    '                End If
                 Let WsPop.Range("A" & Nr & "").Value = strURL
                    
                Else ' Got a dup
    '             Let WsPop.Range("C" & Nr & "").Value = WsPop.Range("C" & Nr & "").Value + 1 ' for count of dups
                End If
             Let TextBit = Mid(TextBit, posJpg + 1)
             Let posJpg = InStr(1, TextBit, "hqdefault.jpg", vbBinaryCompare)
            Loop
        Next Cnt   '   ============================
    End Sub

    Here the results:
    All 11 digit unique YouTube bits from hqdefault_jpg for all 9 text files.jpg






    Simple macro to remove the duplicates in column A Edit: NOT NEEDED !!!
    Previously this was done at the start of the main macro to get all the details I want from every video. But it’s a bit more tidier perhaps to do that quickly now, and put the unique values in column B
    So I used this macro
    Code:
    Sub GetUnique11DigitYouTubeFromAandputinB()
    Rem 0 Worksheets info
    Dim WsPop As Worksheet:  Set WsPop = ThisWorkbook.Worksheets.Item("ElevenDigitYT(2)")
    Dim RngWsYT11 As Range: Set RngWsYT11 = WsPop.Range("A1:A692")         '     1008")
    Dim Unics As String
    Dim Cnt As Long
        For Cnt = 2 To 692 ' 1009
            If InStr(1, Unics, RngWsYT11.Item(Cnt).Value2, vbBinaryCompare) = 0 Then ' Check to see if I not got this the 11 digit bit yet .....   but there may be duplicates for the list from each text file as I click a bit above the last link, say on 76th link ,rather than the typical last 79th link, ( if I clicked on the 79th link I would get the unique 11 digit bit for the 79th video twice from the first two text files, by clicking on the 76th link I will get in both the first two text files the 11 digit bit for the 76th 77th 78th and 79th )
             Let RngWsYT11.Item(Cnt).Offset(0, 1).Value2 = RngWsYT11.Item(Cnt).Value2 ' Puts the 11 digit bit in column B if i have not had that 11 digit bit yet
             Let Unics = Unics & RngWsYT11.Item(Cnt).Value2 & " " ' Put the 11 digit bit in a string which i check to see if i got this one already
            Else
             ' already got this 11 digit bit, so leave the row in column B empty
            End If
        Next Cnt
    End Sub
    But it did nothing!! – because of course, the looping in Sub GetPlayListLinksFromTextFileUsinghqdefaultjpg_Popu larPlayList() results in the first few duplicates not being added. Example at the start of the second main outer loop, the 76th 77th 78th and 79th would not get added
    So I can forget that and take column A original to be all unique
    Last edited by DocAElstein; 03-02-2023 at 08:50 PM.

  4. #104
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10

    Second main working coding attempt

    Part 3 How I got all the info I wanted
    Main final macro

    This will be based on the last one, https://excelfox.com/forum/showthrea...ge10#post19712
    https://excelfox.com/forum/showthrea...ll=1#post19712
    https://excelfox.com/forum/showthrea...ge10#post19702
    https://excelfox.com/forum/showthrea...ll=1#post19702 ?????


    As I went along the last time I made some small modifications but it’s basically the same coding:
    Last edited by DocAElstein; 02-25-2023 at 07:36 PM.

  5. #105
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10

    Second main working coding attempt

    Coding discussed in the last post



    Code:
    ' Second main coding
    
    Sub GetStuffFrom11DigitYouTube2()  '  https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube/page11#post19733
    Rem 0 Worksheets info
    Dim WsYT11 As Worksheet: Set WsYT11 = ThisWorkbook.Worksheets("ElevenDigitYT(2)")
    Dim RngWsYT11 As Range: Set RngWsYT11 = WsYT11.Range("A1:A692")
    Dim Cnt As Long
    WsYT11.Activate
    ActiveWindow.Panes(3).Activate ' To get out of top pane and into bottom pane (I have worksheet divided at line 1)  This is so only the bottom pane is scrolled and the first line in pane 1 with the headings in stays there
    Rem 1 The main stuff now - take every 11 digit bit , make a full link of it, scrape all the text and do all the business
        For Cnt = 2 To 692
        'If RngWsYT11.Item(Cnt).Offset(0, 1).Value2 <> "" Then
            With CreateObject("MSXML2.ServerXMLHTTP")  '  .Server - Yasser http://www.eileenslounge.com/viewtopic.php?p=303638#p303638
             .Open "GET", "https://www.youtube.com/watch?v=" & RngWsYT11.Item(Cnt).Value2, False ' '
             .setRequestHeader "User-Agent", "Chrome"  ' - SpeakEasy Mike  https://eileenslounge.com/viewtopic.php?p=303639#p303639
             .send ' varBody:= ' No extra info for type GET. .send actually makes the request
                While .readyState <> 4: DoEvents: Wend ' Allow other processes to run while the web page loads. Think this is part of the True option
            Dim PageSrc As String: Let PageSrc = .responseText ' Save the HTML code in the (Global) variable. ': Range("P1").Value = PageSrc 'For me for a print out copy to text file etc.    The responseText property returns the information requested by the Open method as a text string
            End With
            '_1(ii)  Optional secion  to put the text string into a text file , for ease of code developments and debugging
        Dim FileNum2 As Long: Let FileNum2 = FreeFile(0)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
        Dim PathAndFileName2 As String
         Let PathAndFileName2 = ThisWorkbook.Path & "\SecondAttemptPopular\WieGehtsYouTubeServerChrome" & RngWsYT11.Item(Cnt).Value2 & ".txt" '
        Open PathAndFileName2 For Output As #FileNum2 ' ' The text file will be made if not there, and if it is there and already contains data, then the data will be overwritten
         Print #FileNum2, PageSrc '
         Close #FileNum2
    
    ' If RngWsYT11.Item(Cnt).Offset(0, 1).Value2 = "GWGzz5p5D80" Then Stop In case I want to stop at a particular 11 digit bit for debugging
        Dim TextBit As String ' The idea is to get a chunk of text that seems to have all the info I want
         Let TextBit = Split(PageSrc, "videoDescriptionHeaderRenderer""", 2, vbBinaryCompare)(1)
         'Let TextBit = Mid(TextBit, 1, 600)
         Let TextBit = Mid(TextBit, 1, 1400)
        
        Dim Title As String
    '         Let Title = Split(TextBit, ":{""title"":{""runs"":[{""text"":""", 2, vbBinaryCompare)(1)
    '         'Let Title = Split(Title, """}]},""channel""", 2, vbBinaryCompare)(0)
    '         Let Title = Split(Title, """}", 2, vbBinaryCompare)(0)
    '            If InStr(1, TextBit, """,""navigationEndpoint""", vbBinaryCompare) <> 0 Then
    '            Let Title = Split(TextBit, ":{""title"":{""runs"":[{""text"":""", 2, vbBinaryCompare)(1)
    '            Dim Pos1nav As Long, Pos2nav As Long
    '             Let Pos1nav = InStr(1, Title, """,""navigationEndpoint""", vbBinaryCompare)
    '             Let Pos2nav = InStr(Pos1nav, Title, "{""text"":""", vbBinaryCompare)
    '             Let Title = Left(Title, Pos1nav - 1) & Right(Title, Len(Title) - (Pos2nav + 8))
    '             Let Title = Split(Title, """}", 2, vbBinaryCompare)(0)
    '            Else
    '            End If
    '  That above checked for link text crap, but only worked if the link was at the beginning of the title: If the link was inside it or at the end, we will end up with multiple text bits, (and the link text crap)  I need to join together and ignore link text crap  -  BTW "link text crap" is what comes after the text seen for the link which is needed to make it work, but i don't want it        .... Text1 .. Textseenforlink .. textcrapneededtomakelinkwork  ... Text3    etc
        Dim posTxtTag As Long ' Usually there will be just one bit of   {"text":"    after which come the title, but sometimes there may be a few as in the case of a link in the title..
         Let posTxtTag = InStr(1, TextBit, "{""text"":""", vbBinaryCompare)
            Do While posTxtTag <> 0 And posTxtTag < InStr(1, TextBit, """channel""", vbBinaryCompare) ' hopefully the text    channel  always comes after the title and before anything else I want
            Dim posTxtTagEnd As Long, posTxtTagEnd2 As Long
             Let posTxtTagEnd = InStr(posTxtTag, TextBit, """,""navigationEndpoint", vbBinaryCompare)  ' This gives me the end of the text for the case of a link text
                If posTxtTagEnd = 0 Then Let posTxtTagEnd = 999 ' If I ain't got a link then I make this big so it does not get used
             Let posTxtTagEnd2 = InStr(posTxtTag, TextBit, """}", vbBinaryCompare)  ' mostly this would be the end of a text bit
             Let posTxtTagEnd = Application.WorksheetFunction.Min(posTxtTagEnd, posTxtTagEnd2) ' Whatever text end I have or watever text end comes first will be used
             Let Title = Title & Mid(TextBit, posTxtTag + 9, (posTxtTagEnd - (posTxtTag + 9))) ' mostly this would only be done once, just more times for building the text if its split into bits by the use of a link in the title
             Let posTxtTag = InStr(posTxtTagEnd, TextBit, "{""text"":""", vbBinaryCompare) ' This will mostly be 0, unless text is split into bits by the use of a link in the title
            Loop ' While posTxtTag <> 0
         ' some empirically found Title tidying up
          Let Title = Replace(Title, "\u0026", "&", 1, -1, vbBinaryCompare)
          Let Title = Replace(Title, "\""", " ", 1, -1, vbBinaryCompare)
          Let Title = Replace(Title, "/", " ", 1, -1, vbBinaryCompare)
         Let RngWsYT11.Item(Cnt).Offset(0, 2).Value2 = Title
         Let Title = "" ' If i don't do this the  Title = Title &   coding will keep adding the titles together
         RngWsYT11.Item(Cnt).Offset(0, 2).Select ' This is helpful or else I cant see the worksheet being filled after the first few
        ' To get the next info i use a lot the  Split Split  bit Yasser showed me   https://eileenslounge.com/viewtopic.php?p=303638#p303638
        Dim Views As String
         Let Views = Split(TextBit, """},""views"":{""simpleText"":""", 2, vbBinaryCompare)(1)
         Let Views = Split(Views, " Aufrufe""}", 2, vbBinaryCompare)(0)
         Let Views = Replace(Views, ".", "", 1, -1, vbBinaryCompare) ' I don't like seperators of any kind
         Let RngWsYT11.Item(Cnt).Offset(0, 4).Value2 = Views
        Dim PubDate As String
         Let PubDate = Split(TextBit, "publishDate"":{""simpleText"":""", 2, vbBinaryCompare)(1)
         Let PubDate = Split(PubDate, """},""factoid"":[{", 2, vbBinaryCompare)(0)
         Let RngWsYT11.Item(Cnt).Offset(0, 3).Value2 = PubDate
        ' date nightmares again
        Dim PubDateV2 As Long, Naw As Long ' DateSerial(year, month, day)
        Dim PubDateRaw As String: Let PubDateRaw = Replace(PubDate, "Premiere am ", "", 1, 1, vbBinaryCompare)
         Let PubDateRaw = Replace(PubDateRaw, "Live übertragen am ", "", 1, 1, vbBinaryCompare)
         Let PubDateV2 = DateSerial(Right(PubDateRaw, 4), Mid(PubDateRaw, 4, 2), Left(PubDateRaw, 2))
         Let RngWsYT11.Item(Cnt).Offset(0, 1).Value2 = PubDateV2
         Let Naw = Evaluate("=NOW()"): ' Debug.Print Naw
    '         Debug.Print Format(PubDateV2, "\Da\y i\s " & "dddd")
    '         Debug.Print Format(PubDateV2, "dddd DD mmm YYYY") & " " & Format(Naw, "dddd DD mmm YYYY")
         Let RngWsYT11.Item(Cnt).Offset(0, 3).Value2 = PubDateV2
         Let RngWsYT11.Item(Cnt).Offset(0, 3).Value = PubDate
         Let RngWsYT11.Item(Cnt).Offset(0, 3).Value = Format(PubDateV2, "dddd DD mmm YYYY")
         Let RngWsYT11.Item(Cnt).Offset(0, 5).Value = Int(Views / (Naw - PubDateV2))
        Dim Likeses As String
         Let Likeses = Split(TextBit, "Mag ich\""-Bewertungen""},""accessibilityText"":""", 2, vbBinaryCompare)(1)
         Let Likeses = Split(Likeses, " \""Mag ich\""-Bewertungen", 2, vbBinaryCompare)(0)
            If InStr(1, Likeses, "Keine", vbBinaryCompare) = 0 Then ' Sometimes the likes are not there  or not showmn or something - only happend in a video not from the main author
             'Let RngWsYT11.Item(Cnt).Offset(0, 6).Value = Likeses
             Let RngWsYT11.Item(Cnt).Offset(0, 7).Value = Int(Likeses / (Naw - PubDateV2))
            Else
             Let Likeses = "Keine"
            End If
         Let RngWsYT11.Item(Cnt).Offset(0, 6).Value = Likeses
        RngWsYT11.Parent.Columns("A:H").AutoFit
        'Else
        'End If
        Next Cnt
    End Sub
    Last edited by DocAElstein; 02-25-2023 at 07:35 PM.

  6. #106
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10
    Popular / Video Playlists
    At this stage of the proceedings I am interested to see if and what similarities in terms of the included videos in the two lists there are. ( I always noted that the number of videos always looks the same. )


    Code:
    Sub Find11digitUTbetween2lists()  '  https://excelfox.com/forum/showthread.php/2840-Notes-tests-Scrapping-YouTube/page11#post19734
    Rem 0 Worksheets info
    Dim Ws1 As Worksheet, Ws2 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets("ElevenDigitYT"): Set Ws2 = ThisWorkbook.Worksheets("ElevenDigitYT(2)")
    Dim Rng1 As Range, Rng2 As Range
     Set Rng1 = Ws1.Range("B2:B1027"): Set Rng2 = Ws2.Range("A2:A692")
     Let Rng2.Value = Evaluate("=IF({1},LEFT(" & Rng2.Address & ",11))") ' reset the found rows or other info added
     Rng2.Font.ColorIndex = xlAutomatic
    Rem 1
    Dim aCel As Range
        For Each aCel In Rng2
        Dim Fndit As Range
         Set Fndit = Rng1.Find(What:=aCel.Value, After:=Rng1.Item(1026), LookIn:=xlValues, lookat:=xlPart, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
            If Fndit Is Nothing Then
            
            Else
             Let aCel.Value = aCel.Value & " " & Fndit.Row
             aCel.Font.Color = vbGreen
            End If
        Next aCel
    End Sub


    There were not many missing, and most were missed probably as they were recent ones done after I did the original codings.
    So I just manually went and downloaded some of those to add to all my downloaded files
    Last edited by DocAElstein; 02-25-2023 at 09:16 PM.

  7. #107
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  8. #108
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10
    kdkladjkdj
    Last edited by DocAElstein; 03-02-2023 at 12:06 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  9. #109
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10
    ljdcsljd
    Last edited by DocAElstein; 02-25-2023 at 07:53 PM.

  10. #110
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,323
    Rep Power
    10
    Last edited by DocAElstein; 02-16-2023 at 02:31 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Tests and Notes on Range Referrencing
    By DocAElstein in forum Test Area
    Replies: 70
    Last Post: 02-20-2024, 01:54 AM
  2. Tests and Notes for EMail Threads
    By DocAElstein in forum Test Area
    Replies: 29
    Last Post: 11-15-2022, 04:39 PM
  3. Some Date Notes and Tests
    By DocAElstein in forum Test Area
    Replies: 0
    Last Post: 11-23-2021, 10:40 PM
  4. Replies: 39
    Last Post: 03-20-2018, 04:09 PM
  5. Notes tests. Excel VBA Folder File Search
    By DocAElstein in forum Test Area
    Replies: 39
    Last Post: 03-20-2018, 04:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •