import requests from bs4 import BeautifulSoup import re url = "https://www.yahoo.co.jp/" res = requests.get(url) soup = BeautifulSoup(res.text, "html.parser") elems = soup.find_all(href=re.compile("news.yahoo.co.jp/pickup")) for elem in elems: print(elem.contents[0]) print(elem.attrs['href']) #空のリストを作成 text_news = [] #一覧のリンクを順に処理 for pickup_link in pickup_links: #Pickupページへ遷移しページの情報を取得 pickup_res
![pythonで気軽にwebスクレイピング → 形態素解析 - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/c525194711b2b5c5f0b60ff424064155f007e616/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-412672c5f0600ab9a64263b751f1bc81.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk3MiZoPTM3OCZ0eHQ9cHl0aG9uJUUzJTgxJUE3JUU2JUIwJTk3JUU4JUJCJUJEJUUzJTgxJUFCd2ViJUUzJTgyJUI5JUUzJTgyJUFGJUUzJTgzJUFDJUUzJTgyJUE0JUUzJTgzJTk0JUUzJTgzJUIzJUUzJTgyJUIwJUUzJTgwJTgwJUUyJTg2JTkyJUUzJTgwJTgwJUU1JUJEJUEyJUU2JTg1JThCJUU3JUI0JUEwJUU4JUE3JUEzJUU2JTlFJTkwJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz0wNjI1MTFlYzJkZjRmYTM3MjdhOTM1N2JlMTczY2IwNQ%26mark-x%3D142%26mark-y%3D57%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZoPTc2Jnc9NzcwJnR4dD0lNDBUYWljaGlFbmRvaCZ0eHQtY29sb3I9JTIzMjEyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnM9N2ZhZWM5NWFiN2UzYzI4YTQ5NDU1NzgzZWY3MDk0ZmE%26blend-x%3D142%26blend-y%3D486%26blend-mode%3Dnormal%26s%3Dc4ee27c0fcf49f1cfceff9393659d6ca)