Home>

Scraping the title and URL from the Nikkei newspaper with Python as shown below,
It is output in CSV.
When I output it as CSV, it becomes one line.
How can I output each number of lines in the title?

import requests
from bs4 import BeautifulSoup
When dealing with import csv #csv
with open ("Save location \\ test.csv", "w", newline = "") as f: #C: \\ ... is the save location
    w = csv.writer (f)
    w.writerow (["Title", "URL"])
    html = requests.get (load_url)
    soup = BeautifulSoup (html.content, "html.parser")
    elems = soup.find_all (class_=" story-list-story__info__headline")
for element in elems:
    print (element.text)
    title = element.text
    r = element.find_previous ('a')
    print (load_url + r.get ('href'),'\ n')
    url = load_url + r.get ('href')
    with open ("C: \\ Users \\ sysnet03 \ Desktop \\ test.csv", "w", newline = "") as f:
        w = csv.writer (f)
        w.writerow ([title, url]) `` `Enter the language here
Code

`` ```