Pythonでスクレイピングしようと勉強始めました。
とりあえずBeautifulSoupを使ってのスクレイピングで正規表現を使っての条件分岐ができるようにやってみました。
reモジュール使ってます
#正規表現を使用するためのモジュール
import re
#みんな大好きbeautifulsoup
from bs4 import BeautifulSoup
#getリクエストするためのモジュール
import requests
#↓このブログサイト
url = "https://nashiblog.netlify.app/"
res = requests.get(url)
soup = BeautifulSoup(res.text,"html.parser")
list = soup.find_all("a")
for i in list:
title = i.text.strip()
if re.search(r'Nashi',title):
print title
else:
print "no title"
=>
Nashi Blog
no title
no title
no title
no title
no title
no title
なんとなくでできました。
意外とやればできる