爬取猪价

#encoding="utf:8"
import time
import requests
import yagmail
from lxml.html import etree

def log():
    now_time = time.strftime(
            "%Y-%m-%d", time.localtime()
        )
    print(now_time)

def ma(contents):
    yag = yagmail.SMTP(
    user="***@163.com",
    password="授权码",
    host='smtp.163.com')
    need = ['接收1@qq.com','接收2@qq.com']
    now_time = time.strftime(
            "%Y-%m-%d", time.localtime()
        )
    #time = log()
    yag.send(need, now_time, contents)





def zj():
    url = "https://zhujia.zhuwang.cc/areapriceinfo-130181.shtml"
    html = requests.get(url).text

    obj = etree.HTML(html)
    one_li = obj.xpath('//*[@id="zhujia"]/ul/li[1]/div[2]/b/text()')
    tz = obj.xpath('//*[@id="zhujia"]/ul/li[3]/div[2]/b/text()')
    one_time = obj.xpath('//*[@id="zhujia"]/div[1]/div[1]/span/text()')

    for i in one_li:
        z = i
    for c in tz:
        cc = c
    for b in one_time:
        b.replace(")","")
        time = b
        

    conn = time
    aaa = "今日外三元:"+z+"元/公斤\n今日土猪:"+cc+""
    ma(aaa)

    print(aaa)
zj()

 

posted @ 2021-06-29 09:37  如若华佗在世  阅读(70)  评论(0)    收藏  举报