Skip to content

Instantly share code, notes, and snippets.

@p208p2002
Created March 4, 2019 02:58
Show Gist options
  • Select an option

  • Save p208p2002/4329669d3b7fc13175d06e82f8dfdb3d to your computer and use it in GitHub Desktop.

Select an option

Save p208p2002/4329669d3b7fc13175d06e82f8dfdb3d to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
from urllib.request import urlopen
#func
def getBsObj(url):
try:
html=urlopen(url)
except:
print('open url fail')
return 1
try:
bsObj=BeautifulSoup(html.read(),'html.parser')
except:
print('html parser fail')
return 1
return bsObj
#main
if __name__ == '__main__':
print(getBsObj("https://www.google.com.tw/").prettify())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment