使用下拉列表抓取历史数据

时间:2019-10-06 15:34:32

标签: r

我尝试从https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm?event=reportsSearch.process抓取数据。如您所见,这里有一个下拉菜单来调用历史数据。但是,该链接与日期范围不相关。因此,我无法创建到相关日期并抓取数据的rvest循环。在这种情况下,如何从此页面获取历史药物批准数据?

1 个答案:

答案 0 :(得分:1)

例如,2019年7月的URL似乎是“ https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm?event=reportsSearch.process&rptName=0& reportSelectMonth = 7& reportSelectYear = 2019”,因此您可以创建一个循环数月和年,将它们应用于网址的reportSelectMonth和reportSelectYear部分,并在每个动态创建的网址上调用read_html()?

例如,如果您想要2017年和2018年全年,可以这样做:

protected function showAll(Collection $collection, $code = 200) {
    $collection = $this->resourceData($collection);
    $collection = $this->filterData($collection);
    $collection = $this->sortData($collection);
    $collection = $this->paginate($collection);

    //Calling resourceData() method
    $resource = $this->resourceData($collection);

    $collection = $this->cacheResponse($collection);


    return $this->successResponse([$resource::collection($collection), 'code' => $code], $code);
}