Python 如何获得网站信息,获得六大洲,国家人口排名,按降序排列

Python 如何获得网站信息,获得六大洲,国家人口排名,按降序排列,python,list,selenium,dictionary,xpath,Python,List,Selenium,Dictionary,Xpath,网站: 得到六大洲的国家人口排名,按降序排列。 预期产出: 非洲 非洲 [1.][“布隆迪”蒲隆地 / 布隆迪","11178921“] [2.][“吉布提”吉布地 / 吉布提","887861“] [3.][“科摩罗”葛摩 / 科摩羅","788474“] 五、 五、 五、 亞洲 亚洲 [1.][“中国”中國","1427647786“] [2.][“日本”日本","126573481“] [3.][“大韩民国”南韓","50293439“] 五、 五、 五、 下一步。我该怎么办,我是学Pyt

网站:

得到六大洲的国家人口排名,按降序排列。 预期产出: 非洲 非洲

[1.][“布隆迪”蒲隆地 / 布隆迪","11178921“]

[2.][“吉布提”吉布地 / 吉布提","887861“]

[3.][“科摩罗”葛摩 / 科摩羅","788474“]

五、

五、

五、

亞洲 亚洲

[1.][“中国”中國","1427647786“]

[2.][“日本”日本","126573481“]

[3.][“大韩民国”南韓","50293439“]

五、

五、

五、

下一步。我该怎么办,我是学Python的学生,需要帮助。谢谢

代码:

从selenium导入webdriver
导入时间
从bs4导入BeautifulSoup
导入请求
driver\u path=r'C:\Users\leon\u shih\AppData\Local\Programs\Python\Python36\chromedriver.exe'
driver=webdriver.Chrome(可执行路径=driver\u路径)
驱动程序。获取(“https://www.ifreesite.com/population/")
时间。睡眠(3)
对于驱动程序中的结果0。通过xpath('/*[@class=“if_table starj taggllj”]”查找元素:
打印(结果0.text)
对于驱动程序中的result1。通过xpath('//tr/td/div/span[@class=“stare”]”查找元素:
打印(结果1.text)
对于结果2
需要获取网站信息:


数据a
数据b
中收集的数据。我将留给你们进一步的数据处理

from selenium import webdriver
import os

browser = webdriver.Chrome(executable_path=os.path.abspath(os.getcwd()) + "/chromedriver")
link = 'https://www.ifreesite.com/population/'
browser.get(link)

table = browser.find_element_by_xpath('//*[@id="if_mainboxb"]/div[2]/div/table[1]/tbody/tr/td/table')
data_rows = table.find_elements_by_tag_name('tr')

data_a = []
data_b = []
for element in data_rows:

    # collect continent names
    continents = [name.text for name in element.find_elements_by_class_name('taggllj')]
    if len(continents) > 0:
        data_a.append(continents[0])
        data_b.append(continents[1])

    # collect population data
    population_data = element.text.splitlines()
    if len(population_data) == 4:
        data_a.append(population_data[0])
        data_b.append(population_data[2])
输出:


您期望的输出是什么?到现在为止您尝试了什么吗?代码测试?遇到错误?预期输出:非洲 非洲[1.][“布隆迪”蒲隆地 / 布隆迪","11178921“][2.][“吉布提”吉布地 / 吉布提","887861“][3.][“科摩罗”葛摩 / 科摩羅","788474“]国家人口排名按降序排列。我希望国家人口排名按降序排列。我该怎么办。谢谢。@user13043463请自己做。大部分工作都完成了,剩下的很简单。谢谢你给我更多的数据操作信息。干杯
['非洲', 'Burundi | 11,178,921', 'Djibouti | 887,861', 'Ethiopia | 99,390,750', 'Madagascar | 24,235,390', 'Mauritius | 1,273,212', 'Mozambique | 27,977,863', .....]