Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

आर्टिकल स्क्रैपिंग और क्यूरेशन के लिए पायथन मॉड्यूल Newspaper


हम डेटा माइनिंग, सूचना पुनर्प्राप्ति आदि जैसे विभिन्न डोमेन से वेब पेजों में सामग्री निकाल सकते हैं। समाचार पत्रों और पत्रिकाओं की वेबसाइटों से जानकारी निकालने के लिए हम 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.

  1. प्रतिस्पर्धात्मक कोडिंग के लिए Python सबसे उपयुक्त क्यों है प्रतिस्पर्धात्मक कोडिंग के लिए Python सबसे उपयुक्त क्यों है

    प्रतिस्पर्धात्मक प्रोग्रामिंग को आमतौर पर उपयुक्त डेटा संरचना का उपयोग करके कुशल एल्गोरिदम का उपयोग करने के लिए कोडिंग के रूप में संदर्भित किया जाता है। वे प्रोग्रामर्स के कौशल का कई स्तरों पर परीक्षण करते हैं। एल्गोरिदम और डेटा संरचना की मदद से, आपको आपके द्वारा प्रस्तुत एक काल्पनिक प्रोग्रामिंग

  1. पायथन getpass मॉड्यूल पायथन getpass मॉड्यूल

    पायथन की स्टैंडर्ड लाइब्रेरी के getpass मॉड्यूल में दो फ़ंक्शन्स परिभाषित हैं। वे तब उपयोगी होते हैं जब भी टर्मिनल-आधारित एप्लिकेशन को यूजर क्रेडेंशियल्स मान्य करने के बाद ही एक्ज़ीक्यूट करने की आवश्यकता होती है। getpass() यह फ़ंक्शन यूजर को पासवर्ड दर्ज करने के लिए प्रेरित करता है। डिफ़ॉल्ट रूप से

  1. वेब स्क्रैपिंग के लिए पायथन टूल्स वेब स्क्रैपिंग के लिए पायथन टूल्स

    कंप्यूटर विज्ञान में वेब स्क्रैपिंग का अर्थ वेबसाइटों से डेटा निकालना है। इस तकनीक का उपयोग करके वेब पर असंरचित डेटा को संरचित डेटा में बदलें। पायथन 3 में सबसे आम वेब स्क्रैपिंग टूल्स हैं - Urllib2 Requests BeautifulSoup Lxml Selenium MechanicalSoup Urllib2 - यह टूल पायथन के साथ प्री-इंस्टॉल्ड आत