Skip to content

Instantly share code, notes, and snippets.

@Utshaw
Last active December 27, 2018 06:10
Show Gist options
  • Save Utshaw/1d87262fd18fcb9ad1ebcb56b1b9eb22 to your computer and use it in GitHub Desktop.
Save Utshaw/1d87262fd18fcb9ad1ebcb56b1b9eb22 to your computer and use it in GitHub Desktop.
Python
import bs4 as bs
import urllib.request
source = urllib.request.urlopen('https://pythonprogramming.net/parsememcparseface/')
soup = bs.BeautifulSoup(source, "lxml") # str(soup) gets entire HTML source file
# soup.nav # returns first nav element inside soup
# soup.nav.div # returns first nav's first div element
nav = soup.nav
# nav.get('style') # returns 'style' attribute inside nav element
# nav.find('div') # retrns div tag nested inside nav
# ref: https://www.youtube.com/watch?v=N5vscPTWKOk
virtualenv project_virtual_env # create a virtual environment on current python folder
source ./project_virtual_env/bin/activate # activate virtual environment
which python # now see, python refers to current environment's python
pip list # list all packages on this environment
pip freeze --local # show local dependencies on python environment
pip freeze --local > requirements.txt # Output those to a txt file
deactivate # Get out of virtual environment
rm -rf project_virtual_env
virtualenv -p usr/bin/python project_2_virtual_env # use specific version of python instead of default one
source project_2_virtual_env/bin/activate
pip install -r requirements.txt # install packages from requirements.txt to this virtual environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment