故里 发表于 2021-10-17 11:54:49

这个数据怎样导入MySQL进行可视化

['Full name:', ' AFM Ahsanuddin Chowdhury', '\n', 'Gender:', ' ', 'Male', 'Country:', ' ', 'Bangladesh', ' (8th President)', '\n', 'Terms:', ' ', '1', ') March 27, 1982 to December 10, 1983', 'Political Party:', ' Jatiya Party\n', 'Date of Birth:', ' July 1, 1915', '\n', 'Birth Place:', ' Mymensingh, British Raj', 'Date of Death:', ' August 30, 2001\n', 'Education:', ' University of Dhaka', '\n']
['Full name:', ' Abdel Fattah el-Sisi', '\n', 'Gender:', ' ', 'Male', 'Country:', ' ', 'Egypt', ' ', '\n', 'Terms:', ' ', '1', ') In office since June 8, 2014', 'Political Party:', ' Independent\n', 'Other Political Titles:', ' Deputy Prime Minister of Egypt\n', 'Date of Birth:', ' November 19, 1954', '\n', 'Birth Place:', ' Cairo, Egypt', 'Education:', ' Egyptian Military Academy, U.S. Army War College', '\n']
['Full name:', ' Abdul Hamid', '\n', 'Gender:', ' ', 'Male', 'Country:', ' ', 'Bangladesh', ' (15th President)', '\n', 'Terms:', ' ', '1', ') In office since April 24, 2013', 'Preceded by:', ' ', 'Zillur Rahman', '\n', 'Political Party:', ' Awami League\n', 'Other Political Titles:', ' Speaker of Jatiyo Sangshad\n', 'Date of Birth:', ' January 1, 1944', '\n', 'Birth Place:', ' Mithamain Upazila, Bangladesh', 'Education:', ' University of Dhaka', '\n']
['Full name:', ' Abdul Kalam', '\n', 'Gender:', ' ', 'Male', 'Country:', ' ', 'India', ' (11th President)', '\n', 'Terms:', ' ', '1', ') July 25, 2002 to July 25, 2007', 'Preceded by:', ' ', 'K. R. Narayanan', '\n', 'Succeeded by:', ' ', 'Pratibha Patil', 'Date of Birth:', ' October 15, 1931', '\n', 'Birth Place:', ' Dhanushkodi, Rameswaram']
['Full name:', ' Abdul Rahman Mohammed Arif Aljumaily', '\n', 'Gender:', ' ', 'Male', 'Country:', ' ', 'Iraq', ' (3rd President)', '\n', 'Terms:', ' ', '1', ') April 16, 1966 to July 17, 1968', 'Preceded by:', ' ', 'Abdul Salam Arif', '\n', 'Succeeded by:', ' ', 'Ahmed Hassan al-Bakr', 'Political Party:', ' Arab Socialist Union\n', 'Other Political Titles:', ' Prime Minister of Iraq\n', 'Date of Birth:', ' January 1, 1916', '\n', 'Birth Place:', ' Baghdad, Ottoman Empire', 'Date of Death:', ' August 24, 2007\n']


故里 发表于 2021-10-17 11:55:46

import requests
from lxml import etree


def main():
    base_url = 'https://www.worldpresidentsdb.com'
    url = 'https://www.worldpresidentsdb.com/list/gender/male/'
    headers = {'user-agent': 'firefox'}
    r = requests.get(url, headers=headers)
    html = etree.HTML(r.text)
    psts = html.xpath('//div[@class="list-group"]//@href')
    for pst in psts:
      url = f'{base_url}{pst}'
      r = requests.get(url, headers=headers)
      html = etree.HTML(r.text)
      info = html.xpath('//div/p//text()')
      print(info)


if __name__ == '__main__':
    main()

傻眼貓咪 发表于 2021-10-17 12:45:41

大哥,你该不会是想别人从头到尾帮你写完全部代码吧?(至少发出你的代码,和你遇到的问题吧)

先用 class 区分开来所有资料:
Full Name、Gender、Country、Terms、Date of Birth、Birth Place、Date of Death、Education
再来逐个输入进数据库 SQL 里

suchocolate 发表于 2021-10-17 16:31:20

数据库用来存储数据,可视化要看你的前端的,你想用什么呈现你的数据?

故里 发表于 2021-10-18 11:10:51

可视化弄完了

suchocolate 发表于 2021-10-18 11:56:24

故里 发表于 2021-10-18 11:10
可视化弄完了

你的代码呢?
页: [1]
查看完整版本: 这个数据怎样导入MySQL进行可视化