当前位置: 首页 > news >正文

Ubuntu 下 无界面环境 多进程/多线程 使用DrissionPage

使用wget “https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb” -O chrome.deb 安装chrome

# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: dp.py
@time: 2025/2/20 20:22 
@desc:

wget "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" -O chrome.deb
co.set_argument('--no-sandbox')
"""
from DrissionPage import WebPage, ChromiumOptions, SessionOptions


class DrissionPageDemo(object):
    """

    """

    def __init__(self):
        """

        """
        self.page = None

    def get_page(self, ua=None, cookies=None, incognito=True, time_out=60, headless=True, port=9225, proxy=None):
        """

        :param ua:
        :param cookies:
        :param incognito:
        :param time_out:
        :param headless:
        :return:
        """
        if not self.page:
            co = ChromiumOptions()
            so = SessionOptions()
            if cookies:
                so.set_cookies(cookies)
            if not ua:
                ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
            co.set_user_agent(user_agent=ua)
            co.set_argument('--no-sandbox')
            co.set_argument('--headless=new')
            co.incognito(incognito)
            co.set_browser_path(r"/usr/bin/google-chrome-stable")
            co.headless(True)
            co.set_argument('--guest')
            co.ignore_certificate_errors(incognito)
            co.mute(True)
            # co.set_local_port(port)
            co.auto_port(scope=(port, port + 50))
            if proxy is not None:
                print("proxy:{}".format(proxy))
                co.set_proxy(proxy)
            # co.set_proxy("http://127.0.0.1:7890")

            co.set_timeouts(page_load=time_out)
            self.page = WebPage(chromium_options=co, session_or_options=so)
        return self.page

    def process(self, url, port=9225, proxy=None):
        """

        :param url:
        :return:
        """
        self.get_page(port=port, proxy=proxy)
        self.page.get(url, retry=3, interval=3)
        self.page.wait(5)
        html = self.page.html
        self.page.quit()
        del self.page
        # os.system("pkill -f chrome")
        print("html = ", html)
        return html


if __name__ == '__main__':
    page = DrissionPageDemo()
    url = "https://www.binance.com/en/support/announcement/8665b792cf804a57bb01b6ea11772746"

    page.process(url)

相关文章:

  • 【最新版】啦啦外卖v64系统独立版源码+全部小程序APP端+安装教程
  • 【论文精读】Copy or Not? Reference-Based Face Image Restoration with Fine Details
  • mysql中my.cnf权限不能过大。否则无法生效
  • SOMEIP通信矩阵解读
  • 探索深度学习模型:技术演进、应用与挑战
  • 【C语言】container_of 宏定义
  • 数据集 handpose_x_plus 3D RGB 三维手势多场景
  • Nginx 配置文件解析
  • 内存池项目(1)——前置知识
  • CF2074F Counting Necessary Nodes
  • 电动垂直起降飞行器(eVTOL)
  • 每天五分钟深度学习框架pytorch:搭建LSTM完成时间序列的预测
  • 汉明码:从奇偶校验到错误精确定位的传奇编码
  • 【11408学习记录】英语通知写作速成攻略:框架拆解+宾语从句疑难全破解
  • 21 天 Python 计划:MySQL 库相关操作
  • DB-Mysql中TIMESTAMP与DATETIME的区别
  • 【Flask开发】嘿马文学web完整flask项目第3篇:2.用户认证,2.用户认证【附代码文档】
  • 【STM32单片机】#6 定时器比较输出
  • OceanSim: 基于Isaac Sim GPU 加速水下机器人感知仿真框架
  • 基于SpringBoot酒店管理系统设计和实现(源码+文档+部署讲解)
  • 摄影网站开发背景/简述seo的应用范围
  • 商务网站建设实训报告1600字/互联网营销专业
  • 环球旅行社网站建设规划书论文/软文推广文章范文
  • 网站开发项目合同书/怎么做公司网站
  • 给小说网站做编辑/电商运营公司
  • 独立页面成网站通过/app推广方案策划