DrissionPage
DrissionPage copied to clipboard
无法在Ubuntu上使用, 求助!
Error using Drission page on a ubuntu server (Ubuntu 22.04(LTS) x64)
Code
from DrissionPage import ChromiumPage
from DrissionPage import ChromiumOptions
from DrissionPage.easy_set import set_headless, set_paths
set_headless(True)
set_paths('/usr/bin/chromedriver')
set_paths(debugger_address='127.0.0.1:9515')
co = ChromiumOptions()
co.set_argument('--incognito')
co.set_argument('--no-sandbox')
page = ChromiumPage()
Error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/venv/lib/python3.10/site-packages/DrissionPage/chromium_page.py", line 35, in __init__
super().__init__(addr_driver_opts, tab_id, timeout)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/chromium_base.py", line 50, in __init__
self._connect_browser(tab_id)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/chromium_page.py", line 80, in _connect_browser
connect_browser(self._driver_options)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/commons/browser.py", line 54, in connect_browser
test_connect(ip, port)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/commons/browser.py", line 171, in test_connect
raise BrowserConnectError(f'\n连接浏览器失败,可能原因:\n1、浏览器未启动\n2、{port}端口不是Chromium内核浏览器\n'
DrissionPage.errors.BrowserConnectError:
连接浏览器失败,可能原因:
1、浏览器未启动
2、9515端口不是Chromium内核浏览器
3、该浏览器未允许控制
4、和已打开的浏览器冲突
请尝试用ChromiumOptions指定别的端口和指定浏览器路径
After trying using selenium on the same driver, it works
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path=r'/usr/bin/chromedriver')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://google.com/")
print(driver.title) # Google
configs.ini
[paths]
download_path =
chromedriver_path = /usr/bin/chromedriver
[chrome_options]
debugger_address = 127.0.0.1:9515
binary_location = /usr/bin/google-chrome
arguments = ['--remote-allow-origins=*', '--no-first-run', '--disable-gpu', '--disable-infobars', '--disable-popup-blocking', '--headless=new']
extensions = []
experimental_options = {'prefs': {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}}}
page_load_strategy = normal
user = Default
auto_port = False
system_user_path = False
[session_options]
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'connection': 'keep-alive', 'accept-charset': 'GB2312,utf-8;q=0.7,*;q=0.7'}
[timeouts]
implicit = 10
page_load = 30
script = 30
[proxies]
http =
https =
What could be the possible issue? can you help? Thanks a lot! @g1879
try using chromium browser
try using chromium browser
Hi @sandrocods , can you eleborate more on this?
你搞错了,不需要用chromedriver。你只要设置browser_path
就可以。
如果你使用3.2.32版本,不设置borwser_path
也可以直接使用。
升级到3.2.32版,然后测试以下代码:
from DrissionPage import ChromiumPage
p = ChromiumPage()
p.get('http://g1879.gitee.io/drissionpagedocs')
如果仍然无法使用,可以试试以下代码
from DrissionPage import ChromiumPage, ChromiumOptions
co = ChromiumOptions(browser_path=r'type your browser path here, not chromedriver path',
local_port='9515')
p = ChromiumPage(co)
p.get('http://g1879.gitee.io/drissionpagedocs')
目前已经是 3.2.32版本,如下:
看起来没有browser_path 这个argument?
试了这个,也不行。
from DrissionPage import ChromiumPage
p = ChromiumPage()
是不是我的google-chrome 装错了?要怎么测试? 谢谢帮忙
抱歉,我写漏了set_paths()
,应该是
co = ChromiumOptions().set_paths(browser_path=r'/user/bin/google-chrome')
试了一下,报了一样的错。是什么possible issue?
co = ChromiumOptions().set_paths(browser_path=r'/user/bin/google-chrome').auto_port(True)
p = ChromiumPage(co)
我不知道是什么原因了,我以前用过Ubuntu,是可以正常使用的。我也知道有其他人在用Ubuntu。
同样的问题,求助
那可惜了,DrissionPage是我用过最好用的爬虫包,没有之一
我以前测试过Ubuntu,记得是可以的。我有时间找个Ubnutu试试。
是不是没设置set_headless(True)
p = ChromiumPage(co)
加了set_headless(True), 也报错了
co = ChromiumOptions().set_paths(browser_path=r'/user/bin/google-chrome').auto_port(True).set_headless(True)
p = ChromiumPage(co)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/venv/lib/python3.10/site-packages/DrissionPage/chromium_page.py", line 35, in __init__
super().__init__(addr_driver_opts, tab_id, timeout)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/chromium_base.py", line 50, in __init__
self._connect_browser(tab_id)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/chromium_page.py", line 80, in _connect_browser
connect_browser(self._driver_options)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/commons/browser.py", line 54, in connect_browser
test_connect(ip, port)
File "/root/venv/lib/python3.10/site-packages/DrissionPage/commons/browser.py", line 171, in test_connect
raise BrowserConnectError(f'\n连接浏览器失败,可能原因:\n1、浏览器未启动\n2、{port}端口不是Chromium内核浏览器\n'
DrissionPage.errors.BrowserConnectError:
连接浏览器失败,可能原因:
1、浏览器未启动
2、9601端口不是Chromium内核浏览器
3、该浏览器未允许控制
4、和已打开的浏览器冲突
请尝试用ChromiumOptions指定别的端口和指定浏览器路径
遗憾的是,DrissionPage 是我用过最好用的爬虫包,没有之一
我的已经解决了 DrissionPage import ChromiumPage from DrissionPage import ChromiumOptions from DrissionPage.easy_set import set_headless, set_paths set_headless(True)
co = ChromiumOptions() co.set_paths(browser_path=r'/usr/bin/google-chrome') co.set_argument('--incognito') co.set_argument('--no-sandbox')
page = ChromiumPage(co)
或者可以使用xvfb?
i run on ubuntu, set sandbox
if you run without display set headless, or you can run with xvfb
遗憾的是,DrissionPage 是我用过最好用的爬虫包,没有之一
我的已经解决了 DrissionPage import ChromiumPage from DrissionPage import ChromiumOptions from DrissionPage.easy_set import set_headless, set_paths set_headless(True)
co = ChromiumOptions() co.set_paths(browser_path=r'/usr/bin/google-chrome') co.set_argument('--incognito') co.set_argument('--no-sandbox')
page = ChromiumPage(co)
或者可以使用xvfb?
加了 co.set_argument('--no-sandbox') 还是不行。 xvfb是什么?可以指导一下吗?多谢!
i run on ubuntu, set sandbox
if you run without display set headless, or you can run with xvfb
I have tried adding co.set_argument('--no-sandbox') but it's still not working. can you guide me the way how to run it with xvfb? Thanks!
在debian环境下也遇到了这个问题,我使用的是chromium-driver @g1879 我应该安装的是浏览器还是内核?以及能否在docker环境下使用?
在debian环境下也遇到了这个问题,我使用的是chromium-driver @g1879 我应该安装的是浏览器还是内核?以及能否在docker环境下使用?
@g1879 同样的疑问,请问目前是否支持在Docker容器内使用,还是说目前只能通过IP地址的方式控制宿主机的浏览器。非常感谢。
在debian环境下也遇到了这个问题,我使用的是chromium-driver @g1879 我应该安装的是浏览器还是内核?以及能否在docker环境下使用?
@g1879 同样的疑问,请问目前是否支持在Docker容器内使用,还是说目前只能通过IP地址的方式控制宿主机的浏览器。非常感谢。
我测试可以在docker内使用。但只能使用headless模式 需要安装chrome浏览器和chrome-driver
在debian环境下也遇到了这个问题,我使用的是chromium-driver @g1879 我应该安装的是浏览器还是内核?以及能否在docker环境下使用?
@g1879 同样的疑问,请问目前是否支持在Docker容器内使用,还是说目前只能通过IP地址的方式控制宿主机的浏览器。非常感谢。
我测试可以在docker内使用。但只能使用headless模式 需要安装chrome浏览器和chrome-driver
可以请问一下在Docker容器内正确安装和部署Chrome及Chrome-driver的方法吗,我尝试了可以查到的办法,使用DrissionPage创建对象的时候总是报和主楼一样的错误。非常感谢你的回复。
@Alen-QK 使用下面的dockerfile即可构建,我尝试了下是完全可行的
FROM python:3.11-slim
WORKDIR /app
# 更换镜像源,不需要可以屏蔽
COPY sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y gnupg2 curl wget unzip ca-certificates
# 安装 Chrome WebDriver
RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
rm /tmp/chromedriver_linux64.zip && \
chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \
ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver
# 安装 Chrome browser
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get -y update && \
apt-get -y install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
#下面是方便调试的设置,不需要可以修改
RUN pip install DrissionPage
CMD tail -f /dev/null
不过需要使用headless的模式才能正确在linux里面使用。这个需要注意下
@Alen-QK 使用下面的dockerfile即可构建,我尝试了下是完全可行的
FROM python:3.11-slim WORKDIR /app # 更换镜像源,不需要可以屏蔽 COPY sources.list /etc/apt/sources.list RUN apt-get update && apt-get install -y gnupg2 curl wget unzip ca-certificates # 安装 Chrome WebDriver RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \ mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \ curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \ unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \ rm /tmp/chromedriver_linux64.zip && \ chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \ ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver # 安装 Chrome browser RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \ apt-get -y update && \ apt-get -y install google-chrome-stable && \ rm -rf /var/lib/apt/lists/* #下面是方便调试的设置,不需要可以修改 RUN pip install DrissionPage CMD tail -f /dev/null
不过需要使用headless的模式才能正确在linux里面使用。这个需要注意下
十分感谢这么细致的回复,有效解决了在Docker容器里的运行问题!Thanks a lot!
我有時候也會出現這個問題,但重啟就好了
i run on ubuntu, set sandbox if you run without display set headless, or you can run with xvfb
I have tried adding co.set_argument('--no-sandbox') but it's still not working. can you guide me the way how to run it with xvfb? Thanks!
This worked for me (adding co.set_argument('--no-sandbox')), advising everyone to try this
i run on ubuntu, set sandbox if you run without display set headless, or you can run with xvfb
I have tried adding co.set_argument('--no-sandbox') but it's still not working. can you guide me the way how to run it with xvfb? Thanks!
This worked for me (adding co.set_argument('--no-sandbox')), advising everyone to try this
works for me
co = ChromiumOptions().set_paths(browser_path=r'/usr/bin/google-chrome')
co.set_argument('--no-sandbox')
co.set_headless(True)
这段代码在Ubuntu、Centos系统下都测过,可以用,Docker内不行,应该是浏览器的browser_path没设置对
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')
I was trying to run it in arm64 ubuntu vm, got error. I tried running with --no-sandbox and it didn't work at first. Then I solved it with deleting the extra port parameter from
co = ChromiumOptions().set_paths(browser_path=r'/user/bin/google-chrome', local_port='9515')
so I just used co = ChromiumOptions().set_paths(browser_path=r'/user/bin/google-chrome')
with adding --no-sandbox to the options also and it worked.
我在ubuntu中也出现这个问题,我注释掉无头模式并且下载了xmanager,使用x11转移,可以在有图形化的系统中看到服务器传过来的浏览器图像,现象是DrissionPage可以打开浏览器但是无法连接,我的代码如下:
co = ChromiumOptions() co.set_paths(browser_path=r'/opt/google/chrome/google-chrome') co.set_argument('--no-sandbox') # 无沙盒模式 # co.set_argument('--headless=new') # 无头 co.set_argument('--remote-debugging-port=9222') # 端口设置 co.set_argument('--disable-gpu') # 无gpu page = ChromiumPage(co) page.get("https://cn.bing.com/")
浏览器路径设置没有问题并且跟--no-sandbox这个参数也无关,然后我更换了端口就发现可以正常连接打开网页了,修改后的代码如下:
co = ChromiumOptions() co.set_paths(browser_path=r'/opt/google/chrome/google-chrome') co.set_argument('--no-sandbox') # 无沙盒模式 # co.set_argument('--headless=new') # 无头 co.set_argument('--remote-debugging-port=9300') # 端口设置 co.set_argument('--disable-gpu') # 无gpu co.set_local_port("9300") page = ChromiumPage(co) page.get("https://cn.bing.com/")
chromium
好像是这个问题,我使用autoport 就无法链接,但是不设置autoport,就可以了,感觉很奇怪 是设置有端口链接,就会出现问题