Scraping with Python

I had to scrape it in Python, so make a note of it. Prepare the environment with Docker and implement it.

Constitution


$ ls
README.md  docker-compose.yaml  scraping
$ ls scraping/
Dockerfile  requirements.txt  scrap.py  scraping.py

docker-compose.yaml


version: '3.8'

services:
  scraping:
    build: ./scraping

Dockerfile


FROM python:latest

COPY . /work
WORKDIR /work

RUN apt-get update

#Install beautiful soup
RUN pip install -U pip
RUN pip install -r requirements.txt

ENTRYPOINT ["python"]
CMD ["scrap.py"]

requirements.txt


bs4
requests

Get it with h1

scrap.py


import requests
from bs4 import BeautifulSoup

url = "https://www.yahoo.co.jp"
response = requests.get(url)

soup = BeautifulSoup(response.text,"html.parser")

titles = soup.find_all("h1")

for title in titles:
    print(title.text)

Execution result


$ docker-compose up --build
.
.
.
scraping_1  | Yahoo! JAPAN
scraping_1  |Search
scraping_1  |About JavaScript settings
scraping_1  |Recommended browser
scraping_1  |Notice
scraping_1  |Main services
scraping_1  |news
scraping_1  |Major news
scraping_1  |His Majesty the Emperor "Deep Reflection" This year as well
scraping_1  |A love story from a lonely battlefield
scraping_1  |5000 dead without fighting an abandoned island
scraping_1  |Be wary of disaster-grade heat in the afternoon
scraping_1  |Former Recruitment Kobun "Japan and Efforts"
scraping_1  |Lawson stamp purchase rampant background
scraping_1  |Breaking news exchange match Iwaki vs.Kokushikan
scraping_1  |Riseisha finishes summer without losing even once
scraping_1  |Silent prayer at the memorial service
scraping_1  |Information about individuals
scraping_1  |Your status
scraping_1  |Today's date
b-model_scraping_1 exited with code 0

Recommended Posts

Scraping with Python
Scraping with Python
Scraping with Python (preparation)
Try scraping with Python.
Scraping with Python + PhantomJS
Scraping with Selenium [Python]
Scraping with Python + PyQuery
Scraping RSS with Python
[Scraping] Python scraping
I tried scraping with Python
Web scraping with python + JupyterLab
Scraping with selenium in Python
Scraping with Selenium + Python Part 1
Scraping with chromedriver in python
Festive scraping with Python, scrapy
Scraping with Selenium in Python
Scraping with Tor in Python
Scraping weather forecast with python
Scraping with Selenium + Python Part 2
I tried scraping with python
Web scraping beginner with python
Python scraping notes
Scraping with selenium
Try scraping with Python + Beautiful Soup
Scraping with selenium ~ 2 ~
Statistics with python
Scraping with Node, Ruby and Python
Web scraping with Python ① (Scraping prior knowledge)
Scraping with Selenium in Python (Basic)
Python with Go
Scraping with Python, Selenium and Chromedriver
Web scraping with Python First step
I tried web scraping with python.
Scraping with Python and Beautiful Soup
Twilio with Python
Integrate with Python
Python Scraping eBay
Play with 2016-Python
AES256 with python
Tested with Python
Scraping with Selenium
python starts with ()
Python Scraping get_title
with syntax (Python)
Let's do image scraping with Python
Python: Scraping Part 1
Get Qiita trends with Python scraping
Bingo with python
Zundokokiyoshi with python
"Scraping & machine learning with Python" Learning memo
Scraping using Python
Get weather information with Python & scraping
Excel with Python
Microcomputer with Python
Python: Scraping Part 2
Cast with python
Get property information by scraping with python
WEB scraping with Python (for personal notes)
Automate simple tasks with Python Part1 Scraping
Getting Started with Python Web Scraping Practice
I tried scraping Yahoo News with Python