[PYTHON] A memorandum when using beautiful soup

I tried using it

Install with pip install beautiful soup4 I thought it would be okay to use the parser by default, so I used the default html.parser instead of lxml.

import requests
from bs4 import BeautifulSoup
url = input()
html = requests.get(url)
soup = BeautifulSoup(html.content, "html.parser")

Basically this should be fine.

Search

・ Id search (only one can be searched soup.find (id =" id name ") ・ Css selector search (only one can be searched ʻIng.select_one ("css selector name") `

When finding all the elements that match your search If id find_all (id name) with css selector select (.class attribute name) See also: [Differences in how to use find_all () and select () in Beautiful Soup] (https://gammasoft.jp/blog/difference-find-and-select-in-beautiful-soup-of-python/)

When searching for things like <h3 class =" A B "> (having multiple class attributes) with select, use select_one (.A.B).

Recommended Posts

A memorandum when using beautiful soup
[Python] A memorandum of beautiful soup4
[Python] Scraping a table using Beautiful Soup
A memorandum of using eigen3
Beautiful Soup
Knowledge when making a bot using discord.py
A memorandum of using Python's input function
A memorandum of trouble when formatting data
Beautiful Soup memo
Beautiful soup spills
Settings when using Python 3 requests and Beautiful Soup with crostini on Chromebook
A addictive story when using tensorflow on Android
Python variadic memorandum when inheriting a defined class
How to search HTML data using Beautiful Soup
Summary when using Fabric
A memorandum about matplotlib
My Beautiful Soup (Python)
A memorandum when writing experimental code ~ Logging in python
A memorandum about Nan.
SoC FPGA: A small story when using on Linux
A memorandum when an error occurs with pip install
[Python] Delete by specifying a tag with Beautiful Soup
A swampy story when using firebase on AWS lamda
Scraping with Beautiful Soup
Precautions when using Chainer
A memorandum regarding Wifi connection when installing Arch Linux
A memorandum when making a surveillance camera with Raspberry Pi
[Django] A memorandum when you want to communicate asynchronously [Python3]
I got a Value Error when using JUMAN ++ with PyKNP
A story that stumbled when using pip in a proxy environment
A memo when creating a directed graph using Graphviz in Python
[GCP] A memorandum when running a Python program on Cloud Functions
I stumbled when I tried to install Basemap, so a memorandum
Problems when using Elasticsearch as a data source in Redash
When using property, use a class that inherits object (new-style class)
(Personal) points when using ctypes
Environment variables when using Tkinter
When using optparse with iPython
A memorandum of kernel compilation
Time measurement using a clock
A small memorandum of openpyxl
DEBUG settings when using Django
Pepper Tutorial (5): Using a Tablet
A memorandum about correlation [Python]
[Python] How to scrape a local html file and output it as CSV using Beautiful Soup
Using a printer with Debian 10
When using if and when using while
File structure when using serverless-python-requirements
A memorandum about Python mock
A memorandum regarding γ conversion
Use configparser when using API
Table scraping with Beautiful Soup
Crawl practice with Beautiful Soup
Small speedup when using pytorch
I got a TypeError:'int' object is not iterable when using keras
The story that a hash error came out when using Pipenv
A memorandum when I tried to get it automatically with selenium
Precautions when using a list or dictionary as the default argument
A memorandum until using mecab on a machine that cannot use sudo
[Python] Appears when using iterdir () etc. [Errno 20] Not a directory:'*** / .DS_Store'
I get a can't set attribute when using @property in python