From cbeefd910b19ff4987fb43ef281460b658fc3e56 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 17 Jul 2025 10:47:00 +0800 Subject: [PATCH] Thu Jul 17 10:47:00 CST 2025 inscode --- main.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4c0c135..2ea42e3 100644 --- a/main.py +++ b/main.py @@ -1 +1,34 @@ -print('欢迎来到 InsCode') \ No newline at end of file +#!/usr/bin/env/ python +# -*- coding:utf-8 -*- +# [url=home.php?mod=space&uid=686208]@AuThor[/url] : zxy +import time +import requests +from lxml import etree + + +url = "https://mfyx.top/api/search" +headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" +} +org_url = input("请输入知乎盐选文章的分享地址:") +data = {"url": [org_url]} +response = requests.post(url=url, json=data, headers=headers).json() +# print(response) +arc_id = response["id"] +title = response["title"].replace("?", "") +des = response["description"] +new_url = f"https://mfyx.top/archives/{arc_id}" +res = requests.get(new_url, headers=headers).text +# print(res) +# xpath://*[@id="lightgallery"]/p +html = etree.HTML(res) +p = html.xpath('//*[@id="lightgallery"]/p/text()') +# print(type(p), p) +print(f"小主为您找到文章的简介:\n{des}") +time.sleep(3) +start = time.time() +with open(f"{title}.txt", "w", encoding="utf-8") as f: + for each_line in p: + f.write(each_line + "\n") + end = time.time() + print(f"[{title}]文章下载完毕,共耗时{end - start:.2f}秒") \ No newline at end of file -- GitLab