Created
March 4, 2019 02:58
-
-
Save p208p2002/4329669d3b7fc13175d06e82f8dfdb3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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