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
Answer # 1
with open ("C: \\ Users \\ sysnet03 \ Desktop \\ test.csv", "w", newline = "") as f:
with open ("C: \\ Users \\ sysnet03 \ Desktop \\ test.csv", "a", newline = "") as f:
- when scraping with python, it says none
- python 3x - supports garbled characters for web scraping
- python scraping error
- where to write timesleep in python scraping
- about character acquisition by python scraping
- specifying css selector when scraping wikipedia in python
- i want to save the image learned by python scraping
- python scraping consecutive urls and saving as csv
- in movable type, even if you change the output file name of the article in the category directly under the root, it will be inde
- how to assign to list when using python scraping find_all
- python - whether scraping is possible
- python 3x - i want to be able to run a scraping program created in python on a website
- python: an error occurs that the type is different in the output using dict key values
- python - (tensorflow) please tell me how to save and output image data mnist
- i want to output the entry result of tkinter with python
- python scraping error
- python - how to hide the browser by scraping with beautifulsoup
- i can't select checkbox when scraping with python
- python 3x - i want to output the name corresponding to the number entered in the excel file
- python : Incorrect Display CSV file in Excel
- python : Save Password data in CSV file
- python : How to translate str in Int or Float?
- python : I want to get the information of the character displayed in QLISTWidget and create a JSON file
- python : UnicodeEncodeError: 'Charmap' Codec Can't Encode Character '\ U0301' In Position 17: Character Maps To
- python : How to count this and output from the CSV file?
- python : Change data from file saving to another file
- python : CSV data incorrectly displayed.
- python : Add data to existing CSV file for each row
- python : Replacing repetitive ID in dataset