Method 1: Using curl and pup
The first method uses two command line tools, curl and pup. Curl is a tool to transfer data from or to a server, while pup is a command line tool for processing HTML. Here’s how to use them together to get a Wikipedia article summary:
- Open your terminal and type the following command:
curl -s "https://en.wikipedia.org/wiki/$(echo "your search query" | sed 's/ /_/g')" | pup 'div.mw-parser-output > p:nth-of-type(1)'
- Replace “your search query” with the title of the Wikipedia article you want to search for.
Method 2: Using Wikit
Another method is to use Wikit, a command line tool for searching and reading Wikipedia articles. Here’s how to use it:
- Install Wikit by typing the following command in your terminal:
sudo apt-get install wikit
wikit "your search query"
- Replace “your search query” with the title of the Wikipedia article you want to search for.
FAQs
1. Can I use these methods to get summaries of articles in other languages?
Yes, you can. Just replace “en” in the Wikipedia URL with the language code of the Wikipedia language you want to search in.
2. What if I want to get a summary of a specific section in the article?
You can modify the selector in the pup command in method 1 to select the specific section you want. For example, to select the summary of the “History” section, you can use the selector ‘div.mw-parser-output > h2:contains(“History”) + p’.
3. Is there a limit to the length of the summary I can get?
Yes, both methods return only the first paragraph of the article, which is usually a summary. If you want to get more content, you’ll need to use a different method or tool.
Conclusion
Getting a Wikipedia article summary in the Linux command line is quick and easy with these methods. Whether you prefer curl and pup or Wikit, you can now access Wikipedia information without leaving your terminal.