위의 두 글을 참고하면 웹페이지의 특정 class에 해당하는 부분을 추출하여 텔레그램 채널로 보내는 것이 가능하다. (두둥)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup # beautiful soup 초기화 soup = BeautifulSoup(r.text, "html.parser" ) # class로 찾기 mr = soup.find( class_ = "bash" ) result = mr.get_text() result_utf8 = result.encode( "UTF-8" ) # 텔레그램 채널로 전송 headers = { "Content-type" : "application/json" } params = '{"chat_id": "@<채널 ID>", "text": "텍스트 추출 : %s"}' % result_utf8 r = requests.post(url, headers = headers, data = params) print (r.text) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup # beautiful soup 초기화 soup = BeautifulSoup(r.text, "html.parser" ) # class로 찾기 mr = soup.find( class_ = "bash" ) result = mr.get_text() # 텔레그램 채널로 전송 headers = { "Content-type" : "application/json" } params = '{"chat_id": "@<채널 ID>", "text": "텍스트 추출 : %s"}' % result r = requests.post(url, headers = headers, data = params.encode( "UTF-8" )) print (r.text) |
테스트 환경 - OS : Windows 7 - Python 버전 : 2.7, 3.6
'1. 연구 모듈 > 텔레그램' 카테고리의 다른 글
텔레그램 봇으로 채널 포스팅 - 8. Python 사용 예제 (3) (0) | 2018.02.20 |
---|---|
텔레그램 봇으로 채널 포스팅 - 7. Clojure 사용 예제 (2) (0) | 2017.09.14 |
텔레그램 봇으로 채널 포스팅 - 5. Clojure 사용 예제 (1) (0) | 2016.12.14 |
텔레그램 봇으로 채널 포스팅 - 4. Python 사용 예제 (1) (1) | 2016.12.13 |
텔레그램 봇으로 채널 포스팅 - 3. Node.js 사용 예제 (2) (0) | 2016.10.06 |