python 邮箱

  import json
from bs4 import BeautifulSoup
import requests
def el(yy):
    from email.header import Header
    from email.mime.text import MIMEText
    from email.utils import parseaddr, formataddr
    def _format_addr(s):
        name, addr = parseaddr(s)
        return formataddr((Header(name, 'utf-8').encode(), addr))

    from_addr = "ajin@qq.com"
    password = ""
    to_addr = "104533538@qq.com"
    html="<table>"
    for i in yy:
        html =html+"<tr>"
        for t in i:
            html=html+"<td>"+t+"</td>"
        html = html+"<tr>"
    html=html+"</table>"
    # print(str(html))
    msg = MIMEText(str(html), 'html', 'utf-8')
    msg['From'] = _format_addr('admin <%s>' % from_addr)
    msg['To'] = _format_addr('you <%s>' % to_addr)
    msg['Subject'] = Header('xinhaiadmin', 'utf-8').encode()
    import smtplib
    server = smtplib.SMTP_SSL("smtp.qq.com", 465)
    server.set_debuglevel(1)
    server.login(from_addr, password)
    server.sendmail(from_addr, [to_addr], msg.as_string())
    server.quit()

url = 'http://wcphp172.xinhaimobile.cn/xh_groupbuy/on-line/xh_shop/admin/index.php?xh_name=&xh_status=2'
res = requests.get(url)
res.encoding='utf-8'
soup = BeautifulSoup(str(res.text), 'html.parser', from_encoding='utf-8')
# print(soup.select('tbody')[0].select('tr')[0].text.replace("\n", ","))
arr1=[]
result = soup.select('thead')[0].select('tr')[0].text.replace("\n", ",").split(',')
arr1.append(result)
shu =soup.select('.rows')[0].text[2:3]
f = open('./a.txt', 'r')
sr=f.read()

if str(sr) <= str(shu):
        t = open('./a.txt', 'w+')
        t.write(str(shu))
        for ty in range(int(soup.select('.rows')[0].text[2:4])+1):
            if ty>0:
                url1 = 'http://wcphp172.xinhaimobile.cn/xh_groupbuy/on-line/xh_shop/admin/index.php?xh_name=&xh_status=2&page='+str(ty)
                res1 = requests.get(url1)
                res1.encoding = 'utf-8'
                soup1 = BeautifulSoup(str(res1.text), 'html.parser', from_encoding='utf-8')
                for i in soup1.select('tbody'):
                    for t in i.select('tr'):
                            arr1.append(t.text.replace("\n", ",").replace(" ", "").replace(" ", "").split(','))


        for w in arr1:
            for t in range(w.count('')):
                w.remove('')
        el(arr1)



评论

刷新

友情链接