在R网站抓取中如何处理onclick javascript事件

在R网站抓取中如何处理onclick javascript事件,javascript,php,r,web-scraping,web,Javascript,Php,R,Web Scraping,Web,我有这个计划,以网络刮网站之一,并为本年度的数据工作良好。但是对于上一年的数据,它们有“今年”下拉列表,这允许您选择需要查看数据的年份,但问题是它不会改变年份。 我注意到,他们在代码的开头有一个onclick=“javascript:return post\u chg\u year函数,我相信这就是关键所在 现在的问题是,我如何在代码中调用这个函数来反映同一年的变化 网站代码: <select name="keystat_yrc" id="keystat_yrc"> <opti

我有这个计划,以网络刮网站之一,并为本年度的数据工作良好。但是对于上一年的数据,它们有“今年”下拉列表,这允许您选择需要查看数据的年份,但问题是它不会改变年份。 我注意到,他们在代码的开头有一个
onclick=“javascript:return post\u chg\u year
函数,我相信这就是关键所在

现在的问题是,我如何在代码中调用这个函数来反映同一年的变化

网站代码:

<select name="keystat_yrc" id="keystat_yrc">
<option value=''>Select</option><option value='2018' >2018</option><option value='2017' >2017</option><option value='2016' >2016</option> …</select>
<img src="goBut3.gif" border="0" onclick="javascript:return post_chg_year('keystats');" align="absmiddle">
<a href="#" class="btnNext" rel="1"></a></h2>
</th>
</tr>
<tr>
<th>Year<br>Ended</th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/equity' target='data_bank'>Equity<br><font size='1'>(Rs Cr)</font></a> <span class='ar'></span></th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/bv' target='data_bank'>BV</a> <span class='ar'></span></th>
<th>Face<br>Value</th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/dividend' target='data_bank'>Dividend</a> <span class='ar'></span></th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/prom-holding' target='data_bank'>Promoters<br>Holding</a> <span class='ar'></span></th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/ronw' target='data_bank'>RONW</a> <span class='ar'></span></th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/roce' target='data_bank'>ROCE</a> <span class='ar'></span></th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/dte' target='data_bank'>Debt to Equity</a> <span class='ar'></span></th>
<th><a href='/stocks/data-bank/standalone/auto-2-3-wheelers/1/keystats/mktcap-sto' target='data_bank'>Market Cap/Sales</a> <span class='ar'></span></th>
<th>&nbsp;</th>

选择201820172016…
年度
结束 面
我的R代码:

SectorList <- read.csv("/SectorList.csv",header = TRUE, sep = ",")
SectorList <- as.data.frame(SectorList)
n <- 112

for (n in 1:n) {
Sector_Name <- as.character(SectorList[n,1])
SectorID <- as.character(SectorList[n,2])

aUrl <- paste0("https://www.moneycontrol.com/stocks/data-bank/standalone/",SectorID,"/1/keystats/equity")
bUrl <- paste0("https://www.moneycontrol.com/stocks/data-bank/standalone/",SectorID,"/1/annual/equity")
cUrl <- paste0("https://www.moneycontrol.com/stocks/data-bank/standalone/",SectorID,"/1/quarterly/equity”)
dUrl <- paste0("https://www.moneycontrol.com/stocks/data-bank/standalone/",SectorID,"/1/mkt-data/equity")


#Key Stats Gathering
acon <- getURL(aUrl, ssl.verifyhost=FALSE, ssl.verifypeer = FALSE)
awebpage <- read_html(acon)

a <- awebpage %>%
html_nodes("table.cntTbls_lrg") %>%
html_nodes("td") %>%
html_text() %>%
gsub("^\\s+|\\s+$","",.)

if(length(a)==0){
next
} 

SectorList你能提供一个我们可以访问的完整url的例子吗有一个网页,当你展开4列时,你会在表格顶部看到year下拉列表……我做了一个很好的尝试,但找不到一个方法。我可以看到一个名为
post\u chg\u year
的函数,它似乎沿着
“/stocks/databank”的行构造了一个url/“+disp_call_type+”/“+url_sel_subsector+”/“+call_type+”/“+tab+”/name”
。我试图通过尽可能地填充参数来重建它(我不是javascript专家或php专家),但我无法让它工作。以下是我的最佳尝试(但似乎不起作用)
https://www.moneycontrol.com/stocks/data-bank/standalone/auto-2-3-wheelers/1/annual/annual_yrc
谢谢您的尝试。。我希望从懂一点java/html/php的人那里得到一些指导