-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
36 lines (28 loc) · 860 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from lxml import html
import requests
import schedule
import time
from aiogram.bot import Bot
from aiogram.types import Message
bot = Bot(token='YOUR_TELEGRAM_BOT_TOKEN')
async def job():
# 爬取网页源码
url = "https://tool.lu/todayonhistory/"
page = requests.get(url)
tree = html.fromstring(page.content)
# 取出所有<li>标签中的内容
tohlis = tree.xpath('//li')
# 遍历所有<li>标签
for li in tohlis:
text = li.text_content()
# 创建搜索 URL
search_url = "http://www.google.com/search?q="
query = text.split(" ")[-1]
url = search_url + query
# 发送消息
await bot.send_message(chat_id='YOUR_CHAT_ID', text=text + ' ' + url)
# 每天8点运行
schedule.every().day.at("8:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)