import requests,json,re
from bs4 import BeautifulSoup as BeautifulSoup
dingtalk_url = “https://oapi.dingtalk.com/robot/send?access_token=856406880ce7735633eebc761d00eabb11fa0ca47cba8de800c74512bc11fdf2"response = requests.get(“http://www.yunweipai.com/“)
soup = BeautifulSoup(response.text,’html.parser’)
div = soup.find_all(‘div’,{‘class’:’title’},{‘a’:’’})
_# print(div)_def send_message(Dingtalk_url, title, message):
    data = {
        ‘msgtype’: ‘markdown’,
        ‘markdown’: {
            ‘title’: ‘%s\n\n’ % title,
            ‘text’: “\n### %s\n\n %s” % (title, message)
        },
        ‘at’: {
            ‘atMobiles’: [],
            ‘isAtAll’: False        }
    }
    response = requests.post(
        Dingtalk_url,
        json=data,
        verify=True)
    print(response.content)
    return response
msg = “\n\n”count = 0btns = []
for i in div[:5]:
    # print(str(i))_    _titleDetail = re.search(‘>(.*?)<’,str(i)).group()
    titleDetail =titleDetail.strip(‘><’).lstrip()
    if re.match(“^http”, i.find(‘a’)[“target”]):
        continue    msg += “ ● %s\n\n\n” % (titleDetail, i.find(‘a’)[“href”])
    count += 1    if count == 5:
        break    print(msg)
send_message(dingtalk_url,”运维派”,msg)
 
                         
                                

