我刚开始使用 docker 并尝试使用 python 运行一个简单的 selenium 测试 但是当我构建图像时,我收到以下错误:
ConnectionRefusedError: [Errno 111] 连接被拒绝
MaxRetryError: HTTPConnectionPool(host='localhost', port=4444)
我做错了什么? 我使用以下 docker 命令来构建:
docker-compose up --build --abort-on-container-exit
我已经尝试为我的本地 IP 地址更改“localhost:4444”,但没有成功
我的 DOCKERFILE
# URL to be scraped
url = "https://basketball.fantasysports.yahoo.com/nba/75810/1"
# this is the HTML from the given URL
html = urlopen(url)
soup = BeautifulSoup(html, "html.parser")
# use findALL() to get the column headers
soup.findAll('tr')
# use getText()to extract the text we need into a list
headers = [th.getText() for th in soup.findAll('tr')[0].findAll('th')]
# avoid the first header row
rows = soup.findAll('tr')[1:]
team_stats_advanced = [[td.getText() for td in rows[i].findAll('td')]
for i in range(len(rows))]
# create data frames
advancedstats = pd.DataFrame(team_stats_advanced[1:], columns = headers)
docker-compose.yml
FROM python:3.8-buster
RUN apt-get update && \
apt-get -y install python3-pandas
COPY ./requirements.txt /requirements.txt
RUN pip install -r requirements.txt
RUN mkdir /app
COPY ./app /app
WORKDIR /app
python 脚本
version: "3"
services:
chromedriver:
image: selenium/standalone-chrome
ports:
- "4444:4444"
steam_parser:
build: .
command: python sample.py
volumes:
- ./app:/app
links:
- chromedriver