Я пытаюсь автоматизировать некоторые из моих работ.
Рассматриваемый веб-сайт представляет собой training.gov.au, где под определенными страницами они размещают таблицу, например. https://training.gov.au/Training/Details/BSBWHS402
На самом деле я хочу указать, с каким модулем я хочу работать (в данном случае BSBWHS402) и перебрать конкретные таблицы, вложенные в эту страницу, а затем преобразовать эти таблицы в CSV или, в идеале, превратить в предварительно отформатированный. документ
Мне удалось немного получить то, что мне нужно, из кода, разделывая чужую работу, но не могу заставить его выглядеть похожим на сайт в таблице.
Я пытался просто вставить в .csv и использовать разделители, но это не работает и, очевидно, на самом деле не автоматизирует его.
import requests
from bs4 import BeautifulSoup
import pandas as pd
import csv
website_url = requests.get('https://training.gov.au/Training/Details/BSBWHS402').text
soup = BeautifulSoup(website_url,'lxml')
tables = soup.findAll('table')
My_table = soup.find('Elements and Performance Criteria')
df = pd.read_html(str(tables))
results = (df[8].to_json(orient='records'))
print(results)
Я получаю следующую единственную строку;
[{"0":"ELEMENT","1":"PERFORMANCE CRITERIA"},{"0":"Elements describe the essential outcomes.","1":"Performance criteria describe the performance needed to demonstrate achievement of the element."},{"0":"1 Assist with determining the legal framework for WHS in the workplace","1":"1.1 Access current WHS legislation and related documentation relevant to the organisation\u2019s operations 1.2 Use knowledge of the relationship between WHS Acts, regulations, codes of practice, standards and guidance material to assist with determining legal requirements in the workplace 1.3 Assist with identifying and confirming the duties, rights and obligations of individuals and parties as specified in legislation 1.4 Assist with seeking advice from legal advisers where necessary"},{"0":"2 Assist with providing advice on WHS compliance","1":"2.1 Assist with providing advice to individuals and parties about their legal duties, rights and obligations, and the location of relevant information in WHS legislation 2.2 Assist with providing advice to individuals and parties about the functions and powers of the WHS regulator and how they are exercised, and the objectives and principles underpinning WHS"},{"0":"3 Assist with WHS legislation compliance measures","1":"3.1 Assist with assessing how the workplace complies with relevant WHS legislation 3.2 Assist with determining the WHS training needs of individuals and parties, and with providing training to meet legal and other requirements 3.3 Assist with developing and implementing changes to workplace policies, procedures, processes and systems that will achieve compliance"}]
Я не уверен, как именно с этим работать, но я могу, по крайней мере, заметить, что он дал распределение, в каком столбце он должен находиться.
Очень открыт для критики и идей о том, как сделать этот продукт лучше.
Я собираюсь сделать пользовательский интерфейс для этого, чтобы ввести имя модуля, но это проблема будущего меня.
Заранее спасибо