1 Star 0 Fork 4

HuTu_chongchong/stata_do

forked from songbl/stata_do 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sblsf.do 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
松柏林 提交于 2021-07-20 20:53 . 浏览论坛:The Stata Forums
qui{
preserve
if "`cls'"!=""{
cls
}
if "`page'"==""{
local page=1
}
if "`page'"!=""{
if `page'==1{
local url http://www.statalist.org/forums/forum/general-stata-discussion/general
}
else {
local url http://www.statalist.org/forums/forum/general-stata-discussion/general/page`page'
}
}
if "`sort'"!=""{
if "`sort'"=="title"{
local url="`url'"+"?filter_sort=title"
}
else if "`sort'"=="last"{
local url="`url'"+"?filter_sort=lastcontent"
}
else if "`sort'"=="start"{
local url="`url'"+"?filter_sort=created"
}
else if "`sort'"=="replie"{
local url="`url'"+"?filter_sort=replies"
}
else if "`sort'"=="member"{
local url="`url'"+"?filter_sort=author"
}
else if "`sort'"=="like"{
local url="`url'"+"?filter_sort=votes"
}
else{
dis as error `"sort() : invalid sort type"'
exit 198
}
}
clear
tempfile html_text
cap copy "`url'" "`html_text'.txt", replace
local times = 0
while _rc ~= 0 {
local times = `times' + 1
sleep 1000
cap copy `"`URL'"' "`html_text'.txt", replace
if `times' > 5 {
n dis as text _col(3) `"{browse "`url'":(contacting https://www.statalist.org/forums)}"'
disp as error "Internet speeds is too low to get the data"
exit 601
}
}
infix strL v 1-100000 using "`html_text'.txt", clear
keep if index(v, "js-topic-title") | index(v, "posts-count") | index(v, "views-count")
gen id = int((_n - 1)/3) + 1
egen year = seq(), from(1) to(3)
reshape wide v, i(id) j(year)
compress
drop id
replace v2 = ustrregexra(v2, ",","")
replace v3 = ustrregexra(v3, ",","")
gen post = ustrregexs(0) if ustrregexm(v2, "\d+$")
gen view = ustrregexs(0) if ustrregexm(v3, "\d+$")
rename v1 v
drop v2 v3
split v, p(`"<a href=""')
split v2, p(`"" class="topic-title js-topic-title">"')
split v22, p("</a>")
rename v21 link
rename v221 title
*replace title = ustrregexra(title, `"""',"")
*replace title = ustrregexra(title, "`","")
*replace title = ustrregexra(title, "'","")
keep link title post view
n dis as text _skip(70) "{bf:Hello, Songbl Stata}"
n dis as txt "{hline}"
n dis in text _col(5) "{bf:Topics}" _col(135) `"{bf:Posts}"' _col(145) `"{bf:Views}"'
n dis as txt "{hline}"
local n=_N
forvalues i = 1/`n' {
local link =link[`i']
local title=title[`i']
local post =post[`i']
local view =view[`i']
if "`line'"!=""{
n dis as text _col(2) `"{browse `"`link'"':- }"' _col(4) `"`title'"' _col(135) "`post'" _col(145) "`view'"
}
else{
n dis as red _col(4) `"{browse `"`link'"': `title'}"' _col(135) "`post'" _col(145) "`view'"
}
if "`gap'"!=""{
n dis ""
}
}
n dis as txt "{hline}"
n dis as text _col(3) `"{browse "`url'":(contacting https://www.statalist.org/forums)}"' _n
restore
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/HuTu_chongchong/stata_do.git
[email protected]:HuTu_chongchong/stata_do.git
HuTu_chongchong
stata_do
stata_do
master

搜索帮助