Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- from newsplease import NewsPlease
- # Define the list of article URLs
- article_urls = [
- "https://www.chinadaily.com.cn/a/202403/18/WS65f7953ba31082fc043bd1ff.html",
- "https://www.chinadaily.com.cn/a/202403/11/WS65ee6fb3a31082fc043bbdfb.html",
- "https://global.chinadaily.com.cn/a/202312/04/WS656d3979a31090682a5f1495.html",
- "https://global.chinadaily.com.cn/a/202305/22/WS646b08a1a310b6054fad467d.html",
- "https://www.globaltimes.cn/page/202403/1308306.shtml",
- "https://www.globaltimes.cn/page/202403/1308489.shtml",
- "https://www.globaltimes.cn/page/202304/1289190.shtml",
- "https://news.cgtn.com/news/2023-09-28/Analysis-Will-the-world-accept-the-Huawei-subculture--1ntsjwCb5Sg/index.html",
- "https://news.cgtn.com/news/2020-09-16/Can-Huawei-survive-the-U-S-chip-ban--TPVMNJdWq4/index.html",
- "https://news.cgtn.com/news/2019-06-29/Ending-the-Huawei-ban-is-common-sense-HVoQ4nz3Xi/index.html",
- ]
- # Create a list to store the article information
- articles_data = []
- # Iterate over the article URLs
- for url in article_urls:
- # Use news-please to extract information from the article
- article = NewsPlease.from_url(url)
- # Extract the desired information
- title = article.title
- authors = ', '.join(article.authors) if article.authors else "Unknown"
- date = article.date_publish if article.date_publish else "Unknown"
- source = url.split("//")[-1].split("/")[0] # Extract the domain as the source
- # Append the article information to the list
- articles_data.append([title, authors, date, source, url])
- # Define the CSV file path
- csv_file = "articles_tech.csv"
- # Write the article information to the CSV file
- with open(csv_file, mode='w', newline='', encoding='utf-8') as file:
- writer = csv.writer(file)
- writer.writerow(["Title", "Authors", "Publication Date", "Source", "URL"])
- for article_data in articles_data:
- writer.writerow(article_data)
- print("Data exported to", csv_file)
Advertisement
Add Comment
Please, Sign In to add comment