हम डेटा माइनिंग, सूचना पुनर्प्राप्ति आदि जैसे विभिन्न डोमेन से वेब पेजों में सामग्री निकाल सकते हैं। समाचार पत्रों और पत्रिकाओं की वेबसाइटों से जानकारी निकालने के लिए हम newspaper लाइब्रेरी का उपयोग करने जा रहे हैं।
इस लाइब्रेरी का मुख्य उद्देश्य समाचार पत्रों और इसी तरह की वेबसाइटों से लेखों को निकालना और क्यूरेट करना है।
इंस्टॉलेशन:
Newspaper लाइब्रेरी इंस्टॉलेशन के लिए, अपने टर्मिनल में चलाएं:
$ pip install newspaper3k
lxml निर्भरता के लिए, अपने टर्मिनल में नीचे कमांड चलाएं
$pip install lxml
PIL इंस्टॉल करने के लिए, चलाएं
$pip install Pillow
NLP कॉर्पोरा डाउनलोड किए जाएंगे:
$ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python
पायथन newspaper लाइब्रेरी का उपयोग लेखों से जुड़ी जानकारी एकत्र करने के लिए किया जाता है। इसमें लेखक का नाम, लेख में प्रमुख छवियां, प्रकाशन तिथियां, लेख में मौजूद वीडियो, लेख का वर्णन करने वाले कीवर्ड और लेख का सारांश शामिल है।
# आवश्यक लाइब्रेरी आयात करें from newspaper import Article # url लिंक - जिसे आप निकालना चाहते हैं url = "https://www.wsj.com/articles/lawmakers-to-resume-stalled-border-security-talks-11549901117" # लेख डाउनलोड करें >>> from newspaper import Article >>> url = "https://www.wsj.com/articles/lawmakers-to-resume-stalled-border-security-talks-11549901117" >>> article = Article(url) >>> article.download() # लेख पार्स करें और लेखक का नाम प्राप्त करें >>> article.parse() >>> print(article.authors)
आउटपुट:
['Kristina Peterson', 'Andrew Duehren', 'Natalie Andrews', 'Kristina.Peterson Wsj.Com', 'Andrew.Duehren Wsj.Com', 'Natalie.Andrews Wsj.Com']
# प्रकाशन तिथि निकालें
>>> print("Article Publication Date:")
>>> print(article.publish_date)
# प्रमुख छवियों का URL निकालें
>>> print(article.top_image)
आउटपुट:
https://images.wsj.net/im-51122/social
# NLP का उपयोग करके कीवर्ड निकालें
print("Keywords in the article", article.keywords)
# लेख का सारांश निकालें
print("Article Summary", article.summary)
नीचे पूरा प्रोग्राम है:
from newspaper import Article
url = "https://www.wsj.com/articles/lawmakers-to-resume-stalled-border-security-talks-11549901117"
article = Article(url)
article.download()
article.parse()
print(article.authors)
print("Article Publication Date:")
print(article.publish_date)
print("Major Image in the article:")
print(article.top_image)
article.nlp()
print("Keywords in the article")
print(article.keywords)
print("Article Summary")
print(article.summary)
आउटपुट:
['Kristina Peterson', 'Andrew Duehren', 'Natalie Andrews', 'Kristina.Peterson Wsj.Com', 'Andrew.Duehren Wsj.Com', 'Natalie.Andrews Wsj.Com'] Article Publication Date: None Major Image in the article: https://images.wsj.net/im-51122/social Keywords in the article ['state', 'spending', 'sweeping', 'southern', 'security', 'border', 'principle', 'lawmakers', 'avoid', 'shutdown', 'reach', 'weekendthe', 'fund', 'trump', 'union', 'agreement', 'wall'] Article Summary President Trump made the case in his State of the Union address for the construction of a wall along the southern U.S. border, calling it a "moral issue." Photo: GettyWASHINGTON—Senior lawmakers said Monday night they had reached an agreement in principle on a sweeping deal to end a monthslong fight over border security and avoid a partial government shutdown this weekend. The top four lawmakers on the House and Senate Appropriations Committees emerged after three closed-door meetings Monday and announced that they had agreed to a framework for all seven spending bills whose funding expires at 12:01 a.m. Saturday.