r programming - 从维基百科网络抓取印度所有城镇的列表..维基百科 R 包

r programming - webscraping a list of all towns in india from wikipedia.. Wikipedi R package

所以我正在尝试使用 R 学习网络抓取——我正在使用维基百科网站,我遇到了一个名为 wikipediR 的包。但没有关于如何使用它的示例。

想法是用这个url 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.

同样适用于 table 中的所有城镇,最好采用表格形式。

这可行吗?

这是作业题吗?

根据 Ronak 的建议,rvest 是一个更好的选择。如果您熟悉 html,其他明智的做法是使用 chrome 中的选择器小工具扩展来获得 html相当于..

您正在查看的页面格式不正确..将其放入数据框中很困难..您需要使用 html 标签..

下面的伪代码

  1. 定义网络link
  2. 阅读页面并保存
  3. 提取城镇名称并将其存储为数据框
  4. 使用上面的方法创建超级 link 列表..(模式相同)
  5. 创建一个从每个 link
  6. 中提取数据的函数
  7. 运行 函数在 4
  8. 中创建的列表上