Lecture 10 - Modularization.pdf

Weve replaced pip with pip35 if we have more than one

This preview shows page 3 - 4 out of 4 pages.

The command isn’t identical. We’ve replaced ‘pip’ with ‘pip3.5’. If we have more than one version of Python installed on our machine, adding the version number to pip will assure the package is installed in the correct location. If only one version of Python is installed, then this is unnecessary. Now we can import BeautifulSoup, or parts of BeautifulSoup known as ‘Classes’, into our code and use its functions. To inform Python where to find the module within the file system, we precede our import statement with a from statement indicating where the module can be found: from location import someModule We can use BeautifulSoup and another package that comes with Python, urllib, to get the HTML code from our previous lab: from bs4 import BeautifulSoup from urllib.request import urlopen url = '' page = urlopen(url) soup = BeautifulSoup(page, 'html.parser') result = soup.prettify() print(result) Result: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta content="width=device-width, initial-scale=1.0" name="viewport">
Image of page 3

Subscribe to view the full document.

<meta content="Music Price Guide, Rare Records collectors price guide, a guide to vinyl and cd value" name="description"> We could even add a few more features, like a list, a for
Image of page 4

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern