这篇文章上次修改于 1521 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

将脚本中注释地方更换为中意的房子地址,在Iterm里运行即可。
环境是Mac Python3

import requests
from bs4 import BeautifulSoup
import time
import os
import sys
import random

def get_status():
    zoom_url = "http://www.ziroom.com/x/782610147.html" # 替换地址
    headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"}
    html = requests.get(url=zoom_url,headers=headers)
    room_data = html.text
    html = BeautifulSoup(room_data, 'lxml')
    soup = html.find_all(attrs={"class": "fl", "id": "vulner_0"})
    right_side = html.find_all("aside", attrs={"class": "Z_info_aside"})
    right_side_data = BeautifulSoup(str(right_side[0]), 'lxml')
    res = right_side_data.find_all("i", attrs={"class": "status"})
    return str(res[0])


if __name__ == "__main__":
    while True:
        res = get_status()
        print(res)
        if res != '<i class="status iconicon_release"></i>':
            os.system(10 * 'say "房子状态改变了!请登录APP查看"')
            sys.exit(1)
        time.sleep(random.randrange(1, 30))



'''
释放
<i class="status iconicon_release">

签约
<i class="status iconicon_sign"></i>
'''