问题描述
因此,我尝试使用R学习网络抓取-并且我使用的是Wikipedia网站,我遇到了一个名为WikipediR ..的程序包,但没有有关如何使用它的示例。
这个想法是使用这个网址 https://en.wikipedia.org/wiki/List_of_towns_in_India_by_population
任何人都可以帮助或指导正确的示例。.我对wikipediR软件包特别感兴趣,但未能获得很多教程或示例。
Achhnera,(alternate spelling: Achnera) is a town and a municipal board in Agra district in the Indian state of Uttar Pradesh.
Geography
Achhnera is located at 27.18°N 77.77°E.[4] It has an average elevation of 167 metres (547 feet). It is famous for its cultural values; people of different religions live here. There are many temples which have historic values. Achhnera comes under Tehsil Kiraoli. It is reachable through Agra Jaipur Highway. The city is connected by rail to Agra,Jaipur,Kanpur and Mathura.
The temperature in Achhnera is typical of northern India,with cold nights in winter and heat waves in summer. In winter the temperature drops to 1–2 °C and in summer it rises to 45–47 °C. Rain is always good
Demographics
As of 2011 India census,Achhnera had a population of 22,781,of which males were 12,117 and females were 10,664. Achhnera has an average literacy rate of 58.7%,with 65.8% of the males and 50.7% of females literate. Population in the age group of 0 to 6 years was 3,313. The Scheduled Castes and Scheduled Tribes population were 4,890 and 6 respectively. Achhnera had 3665 households as of 2011
Employment
There are few opportunities of employment in Achnera. People travel to nearby cities like Agra,Mathura,Bharatpur for employment. Achnera is surrounded by villages and the economy mainly depends on agriculture. The agricultural production depends on the weather,rains on proper time
Adalaj is a census town in Gandhinagar district in the Indian state of Gujarat.
Geography
Adalaj is located at 23.17°N 72.58°E.[1] It has an average elevation of 68 metres (223 ft)
Demographics
As of 2001 India census,[2] Adalaj had a population of 9,774. Males constitute 51% of the population and females 49%. Adalaj has an average literacy rate of 61%,higher than the national average of 59.5%; with 59% of the males and 41% of females literate. 15% of the population is under 6 years of age.
对于表格中的所有城镇,最好采用表格形式。
这可行吗?
解决方法
这是一个家庭作业问题吗?
如罗纳克(Ronak)所建议,rvest是一个更好的选择。.如果您熟悉html,则最好在chrome中使用选择器小工具扩展名来获取html等效项。
您正在查看的页面格式不正确。很难将其放入数据框。您需要使用html标签。
伪代码如下
- 定义网络链接
- 阅读页面并存储
- 提取城镇名称并将其存储为数据框
- 使用上述方法创建超链接列表。(模式相同)
- 创建一个从每个链接提取数据的函数
- 在4中创建的列表上运行功能