First of all, sorry for the double post. I have assumed that my question wasn't correctly defined preventing anyone from answering. So here is a second shot ! 
What I am trying to do: I am trying to webscrapp the number of views of a given list of videos on the youtube platform throughout the day (every 30 mins).
How am I proceeding:

Here is the code that I am using:
Thanks for your help!
PS: Link of my previous post : https://www.statalist.org/forums/for...scrapping-data

What I am trying to do: I am trying to webscrapp the number of views of a given list of videos on the youtube platform throughout the day (every 30 mins).
How am I proceeding:
- A loop is going through a list of URL, copying and saving the HTML code into a text file then imported into stata which keep the string in which the number of views appears.
- Windows' task scheduler is used in order to launch this loop every 30 mins.
Here is the code that I am using:
Code:
******** Webscrapping ********
clear
set more off
local D = c(current_date)
local T = subinstr("`T'",":","_",.)
cd U:\Myfile\
mkdir "`D' `T'"
cd "`D' `T'"
set obs 1
g video = "YouTube"
g vues = "10"
g t = 0
order video vues
save "VA_`c(current_date)'", replace
forvalues repeat=1(1)1 {
#delimit ;
foreach video in 2PXEUsz6wHs Am9pavV7q2g 9Z4s-bktMrY RDqrr9GapCk b5BqxjAmJ1M AE3QyMf900I Sm5Ai0WRLXw 5nCIZCdkOaY ovDcJ_MNNkE tOGNNS9s6kA Jbc_gCzzitE UDaWVM1jEXc qhPe8imp1XM Ga8Wfy-dTCQ
mz6qQALSzSA oXmo946xIYA vUO1RDgkVgE 6xqPKUx1WOI xAeusyp9wj0 2BWX2lWY584 dqve5hStevY QEeta0MRv4s us4byQZ3wtE eSRYWDyybqg OLGskr4Gzak SNJ48sQWpMw 8gGQPbS036U OofH9leYhxY
ZO_M5bBQedI LsCcQ-9-jIM PheVrDBDTL4 unIB1_mdzc4 ci8HQFF6d5A vBYUpkCAF-M iOrffWPE3g8 nmWMdr_Vwj8 NBJx3MK-9zY BGbqxCI5kIA YtxOzQEH6WU TdVkHOMvZDc tdjifiWQcu8 sHojJ3strP0
"-RC_f4oEzHc" dgA3PoNiwbY j6_Y77uWtGw 970T1Sd1thc NbC3VOOo1mo IfMuhob6EAU 9uNpkeMlQE0 2Ut97j6-lsE lJ4TMfyeyhk hkPOkWbiqMg hxiQ6M77qN0 DlEdeyd3Pic uqmSV2Wma9U T8goE0yjw2c
{;
#delimit cr
di "https://www.youtube.com/watch?v=`video'"
cap copy "https://www.youtube.com/watch?v=`video'" "`video'.txt", replace
import delimited using "`video'.txt", stringcols(_all) delimiter("þ") varn(noname) clear
keep if strpos(v1, "watch-view-count")
gen vues = substr(v1, strpos(v1,"watch-view-count"),.)
drop v1
keep vues
gen video = "`video'"
gen time = c(current_time)
gen date = c(current_date)
append using "VA_`c(current_date)'"
order time video vues
save "VA_`c(current_date)'", replace
}
replace t = _n
save "VA_`c(current_date)'", replace
save "U:\Myfile\VA_`c(current_date)'", replace
}
exit, STATA
PS: Link of my previous post : https://www.statalist.org/forums/for...scrapping-data

Comment