Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upadded daily horoscope scrapper script #2167
Conversation
TravisBuddy
commented
Jul 3, 2020
|
Hey @Kim-R2O, TravisCI finished with status TravisBuddy Request Identifier: f840e210-bd70-11ea-ab91-9125a069a76b |
|
Cool submission!, Lines 18-23 are the core of your algorithm so let’s put those lines into a function: def horoscope(zodiac_sign: int, day: str = "today") -> str:
url = ('https://www.horoscope.com/us/horoscopes/general/'
f'horoscope-general-daily-{day}.aspx?sign={zodiac_sign}')
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
return soup.find('div', class_= 'main-horoscope').p.textThen move all the input() and print() code into |
| @@ -0,0 +1,28 @@ | |||
| from bs4 import BeautifulSoup as bs | |||
This comment has been minimized.
This comment has been minimized.
cclauss
Jul 3, 2020
Member
| from bs4 import BeautifulSoup as bs | |
| from bs4 import BeautifulSoup |
Nobody likes bs ;-) so use BeautifulSoup instead.
| import requests | ||
|
|
||
| def horoscope(): | ||
| print('Your daily Horoscope. \n') |
This comment has been minimized.
This comment has been minimized.
| s = soup.find('div', class_= 'main-horoscope') | ||
| print('*' * 70) | ||
| print(s.p.text) #horoscope text for chosen Zodiac sign | ||
| except: |
This comment has been minimized.
This comment has been minimized.
cclauss
Jul 3, 2020
Member
Bare except is a really bad idea... https://realpython.com/the-most-diabolical-python-antipattern
code refactoring, script editing
Kim-R2O commentedJul 3, 2020
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.