铁塔运维手册


HTML文件下载

插件下载(不推荐)

铁塔提供插件下载(ReadModeChromeExtension),但是插件下载方法过于低效,常因为浏览器和计算机元素而导致出错、不稳定 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=a37194043afa3c69324c0d666ca26f1f&file=file.png"; width="300"> 坐标点击方式实现

x, y = 1770, 52     #浏览器图标点击
num_seconds = 1
pyautogui.moveTo(x, y, duration=num_seconds)
pyautogui.moveTo(x, y)
pyautogui.click()

x, y = 1393, 150        #阅读模式转换
num_seconds = 1
pyautogui.moveTo(x, y, duration=num_seconds)
pyautogui.moveTo(x, y)
pyautogui.click()

x, y = 19, 249      #点击下载
num_seconds = 2
pyautogui.moveTo(x, y, duration=num_seconds)
pyautogui.moveTo(x, y)
pyautogui.click()

下载

下载路径 C:\下载 每下载一个行业新闻,自动建立行业名文件夹和百度文件夹,HTML文件移动至文件夹内 <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c405ce5b02ce3cdb6c05a81f11b6990d&file=file.png"; width="300">

完整代码

注释代码为图片识别点击,留作备用

def yd():
    import time
    import pyautogui
    from PIL import ImageGrab, Image
    import pandas as pd
    import requests
    from datetime import date
    import json
    import shutil
    import os
    import webbrowser
    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    # 计时
    start_time = time.time()
    sum = 0

    today = date.today()
    print(&quot;今天的日期:&quot;, today)
    try:
        shutil.rmtree('C:\\下载')
        os.mkdir('C:\\下载')
    except:
        os.mkdir('C:\\Users\\z\\Downloads')

    try:
        shutil.rmtree('C:\\铁塔')
        os.mkdir('C:\\铁塔')
    except:
        os.mkdir('C:\\铁塔')

    hy1 = [&quot;长河禁捕&quot;, &quot;农业&quot;, &quot;林业&quot;, &quot;水利&quot;, &quot;环保&quot;, &quot;政法&quot;, &quot;应急&quot;, &quot;国土&quot;, &quot;园区&quot;, &quot;市政&quot;, &quot;能源&quot;, &quot;铁路&quot;, &quot;乡镇&quot;, &quot;电力&quot;, &quot;海洋&quot;, &quot;广告&quot;, &quot;运营商&quot;]
    for hy in hy1:

        lj = 'C:\\铁塔\\' + hy
        lj1 = 'C:\\铁塔\\' + hy + '\\百度'
        os.mkdir(lj)
        os.mkdir(lj1)
        zb = &quot;C:\\铁塔每日新闻记录表\\百度资讯抓取\\&quot; + str(today) + &quot;(1).xlsx&quot;
        zb1 = pd.read_excel(zb, sheet_name=hy, header=0)
        lj = zb1[&quot;链接&quot;].tolist()
        for i in lj:
            print(i)
            webbrowser.open(i, new=0, autoraise=True)
            time.sleep(2)
            # # 事先对按钮截图
            # zhengnengliangImg = Image.open(r&quot;C:\捕获.PNG&quot;)
            # # 截图当前屏幕并找到之前加载的按钮截图
            # msg = pyautogui.locateOnScreen(zhengnengliangImg, grayscale=True, confidence=.9)
            # if msg == None:
            #   print(&quot;没找到&quot;)
            # else:
            #   x, y, width, height = msg
            #   print(&quot;该图标在屏幕中的位置是:X={},Y={},宽{}像素,高{}像素&quot;.format(x, y, width, height))
            #   # 左键点击屏幕上的这个位置
            #   pyautogui.click(x, y, button='left')
            #
            # time.sleep(1)
            # # 事先对按钮截图
            # zhengnengliangImg = Image.open(r&quot;C:\阅读.PNG&quot;)
            # # 截图当前屏幕并找到之前加载的按钮截图
            # msg = pyautogui.locateOnScreen(zhengnengliangImg, grayscale=True, confidence=.9)
            # if msg == None:
            #   print(&quot;没找到&quot;)
            # else:
            #   x, y, width, height = msg
            #   print(&quot;该图标在屏幕中的位置是:X={},Y={},宽{}像素,高{}像素&quot;.format(x, y, width, height))
            #   # 左键点击屏幕上的这个位置
            #   pyautogui.click(x, y, button='left')
            #
            # time.sleep(1)
            # # 事先对按钮截图
            # zhengnengliangImg = Image.open(r&quot;C:\保存.PNG&quot;)
            # # 截图当前屏幕并找到之前加载的按钮截图
            # msg = pyautogui.locateOnScreen(zhengnengliangImg, grayscale=True, confidence=.9)
            # if msg == None:
            #   print(&quot;没找到&quot;)
            # else:
            #   x, y, width, height = msg
            #   print(&quot;该图标在屏幕中的位置是:X={},Y={},宽{}像素,高{}像素&quot;.format(x, y, width, height))
            #   # 左键点击屏幕上的这个位置
            #   pyautogui.click(x, y, button='left')
            x, y = 1770, 52
            num_seconds = 1
            pyautogui.moveTo(x, y, duration=num_seconds)
            pyautogui.moveTo(x, y)
            pyautogui.click()

            x, y = 1393, 150
            num_seconds = 1
            pyautogui.moveTo(x, y, duration=num_seconds)
            pyautogui.moveTo(x, y)
            pyautogui.click()

            x, y = 19, 249
            num_seconds = 2
            pyautogui.moveTo(x, y, duration=num_seconds)
            pyautogui.moveTo(x, y)
            pyautogui.click()

            time.sleep(3)
            os.system(&quot;taskkill /F /IM chrome.exe&quot;)

        old_path = 'C:\\下载\\'  # 原文件夹路径
        new_path = lj1  # 新文件夹路径
        print(old_path)
        print(new_path)
        filelist = os.listdir(old_path)  # 列出该目录下的所有文件,listdir返回的文件列表是不包含路径的。
        print(filelist)
        for file in filelist:
            src = os.path.join(old_path, file)
            dst = os.path.join(new_path, file)
            print('src:', src)  # 原文件路径下的文件
            print('dst:', dst)  # 移动到新的路径下的文件
            shutil.move(src, dst)

页面列表

ITEM_HTML