Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Natural Language Processing Fundamentals

You're reading from   Natural Language Processing Fundamentals Build intelligent applications that can interpret the human language to deliver impactful results

Arrow left icon
Product type Paperback
Published in Mar 2019
Publisher
ISBN-13 9781789954043
Length 374 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Dwight Gunning Dwight Gunning
Author Profile Icon Dwight Gunning
Dwight Gunning
Sohom Ghosh Sohom Ghosh
Author Profile Icon Sohom Ghosh
Sohom Ghosh
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Introduction to Natural Language Processing FREE CHAPTER 2. Basic Feature Extraction Methods 3. Developing a Text classifier 4. Collecting Text Data from the Web 5. Topic Modeling 6. Text Summarization and Text Generation 7. Vector Representation 8. Sentiment Analysis Appendix

Requesting Content from Web Pages

Whenever you visit a web page from your web browser, you actually send a request to fetch its content. This can be done using Python scripts. Packages such as urllib3 and requests are used to do so. Let's look at an exercise to get a better understanding of this concept.

Exercise 41: Collecting Online Text Data

In this exercise, we will collect online data, with the help of requests and urllib3. Follow these steps to implement this exercise:

  1. Use the requests library to request the content of a book available online with the following set of commands:
    import requests
    r = requests.post('https://www.gutenberg.org/files/766/766-0.txt')
    r.status_code

    The preceding code generates the following output:

    Figure 4.10: HTTP status code

    Note

    Here, 200 indicates that we received a proper response from the URL.

  2. To locate the text content of the fetched file, write the following code:
    r.text[:1000]

    The preceding code generates the following...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image