039_py_bs4 - kotaproj/study_zenpan GitHub Wiki

bs4

> python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 16:30:00) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> 
>>> r = requests.get('https://webmanga.info/comic/onepanman')
>>> r.text      
'<!DOCTYPE html>略</body>\n</html>\n'
>>> 
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(r.text, "html.parser") 
>>> for li in soup.find_all("li"):
...   print(li.text)
... 
2021/01/22
1月22日 137話更新
2021/01/20
1月20日 136話更新
2021/01/19
1月19日 135話更新
2021/01/18
1月18日 134話更新
2020/10/20
10月20日 133話更新
>>>

メモ

import re

uls = [
    """・給付金乞食、1枚の画像で論破されるWWW""",
    """2021/01/22
    1月22日 137話更新""",
    """2021/01/20
    1月20日 136話更新""",
    """2021/01/19
    1月19日 135話更新""",
    """2021/01/18
    1月18日 134話更新""",
    """2020/10/20
    10月20日 133話更新"""
]

for ul in uls:
    # print(ul)
    if "話更新" in ul:
        result = re.findall(r"\d+", ul)
        if len(result) == 6:
            print("{}年{}月{}日 - {}話".format(result[0], result[1], result[2], result[-1]))
    print("---")

⚠️ **GitHub.com Fallback** ⚠️