Skip to content

Instantly share code, notes, and snippets.

@ethmtrgt
Last active February 27, 2022 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethmtrgt/1034a80c982c0c7361692f76bdf358e5 to your computer and use it in GitHub Desktop.
Save ethmtrgt/1034a80c982c0c7361692f76bdf358e5 to your computer and use it in GitHub Desktop.
def get_news(update, context):
r = requests.get("https://www.haberler.com/son-dakika/")
soup = BeautifulSoup(r.content, "lxml")
news = soup.find_all('div', attrs={'class':"hblnBox"})
for Kaynak in news[:1]:
Haber = Kaynak.find('span', attrs={'class':'hblnTitle'})
_title_time = Haber.find('div', attrs={'class': 'hblnTitleTime'}) # İstenmeyen kısım
_title_time.extract()
img = Kaynak.find('img').get('src')
my_news = f"{Haber.text}\n{img}"
update.message.reply_text(my_news)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment