<jupyter_start><jupyter_text><jupyter_code>#Yahoo_RSS_Media 見出しスクレイピング
#対象約600サイト、所要10分程度、1・5Ｍ

import pandas as pd
import requests
from bs4 import BeautifulSoup
import re
import csv

df = pd.read_csv( '/content/yahoo_media_list.csv') 

with open("/content/Yahoo_RSS_Media.csv", mode="a", encoding="utf_8_sig",newline='') as f:
  writer = csv.DictWriter(f, ['Media','Title','Link','Pubdate', 'Description'])
  writer.writeheader()
 
  for index, row in df.iterrows():
    url = row['url'] 
    xml = requests.get( url )
    soup = BeautifulSoup(xml.text, 'xml' )

    for news in soup.findAll('item'):
      d = {}
      d["Media"]  = row['media'] 
      d["Title"]  = news.title.string
      d["Link"] = news.link.string
      d["Pubdate"] = news.pubDate.string
      d["Description"]  = "" if news.description == None else news.description.string
      writer.writerow(d)
    


# # # print( "'{}','{}','{}'".format(Nowtime, Headline, Link ))
# # # from datetime import timedelta
#   #  url_list = []<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17151162790697674, 'fraction_numerical': 0.00872093023255814, 'mean_word_length': 3.919047619047619, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '647795', 'license': 'MIT', 'n_tokens_mistral': 394, 'n_tokens_neox': 379, 'n_words': 74, 'path': 'Yahoo_RSS_Media.ipynb', 'repo_name': 'skbnw/chart-doctor', 'size': '1032'}