DrissionPage icon indicating copy to clipboard operation
DrissionPage copied to clipboard

Run the Drission page in Docker and integrate xvfb

Open kreethandsouza opened this issue 1 year ago • 6 comments

Can someone help me with this? I Have this code running in docker. I dont want it to run headless so could someone help me with to use xvfb. what is xvfb and how to integrate it with docker so that i can smoothely run it in docker without headless. Thanks. I dont want it to run headless because i want to access a site which takes some time to load and also has javascript i want the browser not in headless mode.

from DrissionPage import ChromiumPage, ChromiumOptions import os co = ChromiumOptions() co.set_argument('--no-sandbox') chrome = ChromiumPage(co) chrome.get('https://www.google.com')

kreethandsouza avatar Feb 20 '24 04:02 kreethandsouza

pip install PyVirtualDisplay

then add this to the start of your code

from pyvirtualdisplay import Display display = Display(visible=False, size=(1024, 768)) display.start()

nizamelahi avatar Feb 20 '24 09:02 nizamelahi

pip install PyVirtualDisplay

then add this to the start of your code

from pyvirtualdisplay import Display display = Display(visible=False, size=(1024, 768)) display.start()

Nope it didn't work. Im actually trying to break cloudflare in docker container. when i run it in local ubuntu it works but without headless. i want to run the code in docker contianer in headless mode and should bypass cloudflare could you help me with this? thanks.

不,它不起作用。我实际上试图破坏 docker 容器中的 cloudflare。当我在本地 ubuntu 中运行它时,它可以工作,但没有无头。我想在无头模式下在 docker contianer 中运行代码,并且应该绕过 cloudflare 你能帮我吗?谢谢。

kreethandsouza avatar Feb 20 '24 09:02 kreethandsouza

oh my bad i thought you wanted to run it without headless.this code snippet allows you to run this library on a linux system without a gui.as far as i know the library doesnt support bypassing cloudflare in headless mode yet

nizamelahi avatar Feb 20 '24 11:02 nizamelahi

oh my bad i thought you wanted to run it without headless.this code snippet allows you to run this library on a linux system without a gui.as far as i know the library doesnt support bypassing cloudflare in headless mode yet

/bin/sh: systemctl: not found

it will actually throw this error do you know how to resolve it thanks.

FROM python:3.9-alpine3.15

COPY requirements.txt /requirements.txt

RUN apk update
&& apk add --no-cache python3 build-base linux-headers
&& pip install -r requirements.txt
&& apk del build-base linux-headers
&& rm -rf /var/cache/apk/* /root/.cache/*
&& apk add xvfb

RUN apk add --no-cache
chromium
chromium-chromedriver

ENV PATH="/usr/lib/chromium/:${PATH}"

WORKDIR drissionpage

COPY / /drissionpage

this is my docker file

kreethandsouza avatar Feb 21 '24 05:02 kreethandsouza

Have you solved the problem?

MeoMeo0 avatar Aug 02 '24 07:08 MeoMeo0

Hello! I have problem with drissionpage and bypass cloudflare on ubuntu.

My code from DrissionPage import ChromiumPage, ChromiumOptions

    # Настройка опций для браузера

    co = ChromiumOptions()
    co.set_argument('--no-sandbox')

    # Инициализация браузера
    p = ChromiumPage(co)


    # Открытие страницы
    p.get('https://ru.almaviva-visa.services/')
    time.sleep(20)

    # Получение куков
    cookies = p.cookies()

    # Печать всех куков

    # Закрытие браузера

    cf_clearance_value = None
    for cookie in cookies:
        if cookie['name'] == 'cf_clearance':
            cf_clearance_value = cookie['value']
            break

    if cf_clearance_value:
        print(cf_clearance_value)
    else:
        print("Кука cf_clearance не найдена")
    p.quit()
    
    
    error: 
    
    An error occurred: The connection to the page was interrupted. . Restart after 60 seconds.

Anton1Ushakov avatar Aug 11 '24 12:08 Anton1Ushakov