网页table标签数据获取

获取github中网页元素table的数据

  1. // ==UserScript==
  2. // @name 网页table标签数据获取
  3. // @namespace http://tampermonkey.net/
  4. // @license Apache-2.0
  5. // @version 1.0.1
  6. // @author hgz
  7. // @description 获取github中网页元素table的数据
  8. // @icon https://github.com/favicon.ico
  9. // @noframes
  10. // @grant none
  11. // @match *://github.com/*
  12. // ==/UserScript==
  13. "use strict";
  14. const getTable=async ()=>{
  15. const tableEls = document.querySelectorAll('markdown-accessiblity-table table');
  16. const data = [];
  17. for (const tableEl of tableEls) {
  18. const headers = tableEl.querySelectorAll('thead th');
  19. const headerNames = Array.from(headers).map(header => header.textContent);
  20. const rows = tableEl.querySelectorAll('tbody tr');
  21. const jsonArray = Array.from(rows).map(row => {
  22. const cells = row.querySelectorAll('td');
  23. const rowData = {};
  24. headerNames.forEach((header, index) => {
  25. rowData[header] = cells[index].textContent;
  26. });
  27. return rowData;
  28. });
  29. data.push(jsonArray);
  30. }
  31. return data
  32. };
  33. var defUtil = {
  34. getTable
  35. };
  36. const getVideo_zone = async () => {
  37. const data = await defUtil.getTable();
  38. const templateDefineData = {};
  39. for (let datum of data) {
  40. templateDefineData[datum[0]['名称']] = [];
  41. for (let i = 1; i < datum.length - 1; i++) {
  42. templateDefineData[datum[0]['名称']].push(datum[i]['名称']);
  43. }
  44. }
  45. return templateDefineData
  46. };
  47. var bilibiliAPICollect = {
  48. getVideo_zone
  49. };
  50. window.addEventListener('load', () => {
  51. defUtil.getTable().then(data => {
  52. console.log('github页面table数据', data);
  53. });
  54. bilibiliAPICollect.getVideo_zone().then(map => {
  55. console.log('bilibili-API-collect仓库视频分区数据', map);
  56. });
  57. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址