toutiao fans

下载头条粉丝信息表格

目前為 2021-09-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         toutiao fans
// @namespace    http://www.yysheng.com/
// @version      0.8
// @description  下载头条粉丝信息表格
// @author       yysheng
// @match        https://www.toutiao.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
			    'use strict';
				console.log("开始打印")
				console.log(document.getElementsByClassName('list-wrapper'))
				var span = document.createElement('div'); //1、创建元素
				span.style.width = '200px'
				span.style.height = '50px'
				span.style.position = 'fixed'
				span.style.bottom = '0'
				span.style.right = '210px'
				span.style.backgroundColor = 'orange'
				span.style.color = 'black'
				span.style.textAlign = 'center'
				span.style.lineHeight = '50px'
                span.style.zIndex = '20000'
				span.innerHTML='提取';
				document.body.appendChild(span)
				var nameList = []
				var excel = '<table>';
				var row = "<tr>";

				span.onclick = function(){
					console.log("点击了提取")
                    nameList = []
					let arr = document.getElementsByClassName('name')
					for (let i = 0; i < arr.length; i++) {
						let name = arr[i].innerText
						let phone = name.match(/\d+/g)
						if(!phone)continue;
						phone = phone.join('')
						let myreg=/^[1][3,4,5,7,8,9][0-9]{9}$/;
						if (myreg.test(phone)) {
						    console.log(phone)
							nameList.push({name:name,phone:phone})
						}
					}
					span.innerHTML='已提取'+nameList.length+'个';
					console.log(nameList)
				}

				var span2 = document.createElement('div'); //1、创建元素
				span2.style.width = '200px'
				span2.style.height = '50px'
				span2.style.position = 'fixed'
				span2.style.bottom = '0'
				span2.style.right = '0'
				span2.style.backgroundColor = 'orange'
				span2.style.color = 'black'
				span2.style.textAlign = 'center'
				span2.style.lineHeight = '50px'
                span2.style.zIndex = '20000'
				span2.innerHTML='下载';
				document.body.appendChild(span2)
				span2.onclick = function(){
					console.log("点击了下载")
					if(nameList.length < 1){
						alert("没有可下载的粉丝信息")
						return
					}
					//先转化json
					var arrData = typeof nameList != 'object' ? JSON.parse(nameList) : nameList;
					var row = "<tr>";
					//设置表头
					var keys = Object.keys(nameList[0]);
					keys.forEach(function (item) {
					    row += "<td>" + item + '</td>';
					});
					//换行
					excel += row + "</tr>";
					//设置数据
					for (var i = 0; i < arrData.length; i++) {
                        row = "<tr>";
					    for (var index in arrData[i]) {
					        console.log(arrData[i][index]);
					        //var value = arrData[i][index] === "." ? "" : arrData[i][index];
					        row += '<td>' + arrData[i][index] + '</td>';
					    }
					    excel += row + "</tr>";
					}
					excel += "</table>";
					var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
					excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
					excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
					excelFile += '; charset=UTF-8">';
					excelFile += "<head>";
					excelFile += "<!--[if gte mso 9]>";
					excelFile += "<xml>";
					excelFile += "<x:ExcelWorkbook>";
					excelFile += "<x:ExcelWorksheets>";
					excelFile += "<x:ExcelWorksheet>";
					excelFile += "<x:Name>";
					excelFile += "{worksheet}";
					excelFile += "</x:Name>";
					excelFile += "<x:WorksheetOptions>";
					excelFile += "<x:DisplayGridlines/>";
					excelFile += "</x:WorksheetOptions>";
					excelFile += "</x:ExcelWorksheet>";
					excelFile += "</x:ExcelWorksheets>";
					excelFile += "</x:ExcelWorkbook>";
					excelFile += "</xml>";
					excelFile += "<![endif]-->";
					excelFile += "</head>";
					excelFile += "<body>";
					excelFile += excel;
					excelFile += "</body>";
					excelFile += "</html>";

					var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);

					var link = document.createElement("a");
					link.href = uri;

					link.style = "visibility:hidden";
					link.download = "头条粉丝信息.xls";

					document.body.appendChild(link);
					link.click();
					document.body.removeChild(link);
				}

			    // Your code here...
			})();

QingJ © 2025

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