ওয়েব পেজ থেকে কন্টেন্ট এক্সট্রাক্ট করা ডেটা মাইনিং, ইনফরমেশন রিট্রিভাল ইত্যাদি ডোমেইনে খুব প্রয়োজনীয়। নিউজপেপার ও ম্যাগাজিন ওয়েবসাইট থেকে আর্টিকেল এক্সট্রাক্ট এবং কিউরেট করার জন্য 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
Python newspaper লাইব্রেরি আর্টিকেল সম্পর্কিত তথ্য সংগ্রহ করতে ব্যবহৃত হয়—যেমন লেখকের নাম, প্রধান ছবি, প্রকাশনার তারিখ, ভিডিও, কীওয়ার্ড এবং আর্টিকেলের সামারি।
# প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট
from newspaper import Article
# যে URL থেকে এক্সট্রাক্ট করবেন
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: Getty
WASHINGTON—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.