-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle_scrape.py
59 lines (46 loc) · 1.61 KB
/
article_scrape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import newspaper.article
from newspaper import Article
import nltk
from article_nlp import *
import time
# create a function that will summarize the article based on inputted url
def summarize_article(url):
# create an article object based off the url given
article = Article(url)
# download the article and parse it
article.download()
article.parse()
# punkt is a tokenizer which helps extract text
nltk.download('punkt', quiet=True)
article.nlp()
# grab the articles authors
print("Author: " + str(article.authors))
author = str(article.authors)
# get the publishing date of the article and format according to M-D-Y
unf_date = article.publish_date
formatted_date = ""
if unf_date:
formatted_date = str(unf_date.strftime("%m-%d-%Y"))
else:
formatted_date = "No Date Available"
print("Publish Date: " + formatted_date)
# grab the top image of the article
print("Top Image Url: " + str(article.top_image))
top_image = str(article.top_image)
# grab all the images within the article
# image_string = "All Images: "
# for image in article.images:
# image_string += "\n\t" + image
# print(image_string)
print("A Quick Article Summary")
print("----------------------------")
print(article.summary)
# print the sentiment analysis
find_sentiment(article.text)
print("Link to Original Article")
print("----------------------------")
print(url)
print()
# grab the article summary
article_summary = article.summary
return author, formatted_date, top_image, article_summary