【发布时间】:2019-07-29 02:11:16
【问题描述】:
我正在买房子,我已经构建了一个 BeautifulSoup 刮刀,它的作用就像一个魅力 - 从我们当地的房地产网站上刮下我需要的标签。现在我只需要实现一个机制,当网站有变化时会通知我。
一旦新的抓取输出与前一个不同 - 当 HTML 更改时,我需要它通知我。
previous_content = ''
URL = 'whatever.com'
while True:
content = requests.get(URL)
soup = BeautifulSoup(content.text, 'html.parser')
titles = soup.find_all('span', attrs={'class':['title']})
years = soup.find_all('span', attrs={'class':['year']})
sizes = soup.find_all('span', attrs={'class':['size']})
prices = soup.find_all('span', attrs={'class':['price']})
for titles, years, sizes, prices in zip(titles, years, sizes, prices):
print('Location: ' + titles.get_text(strip="True") + '\n' + 'Year: ' + years.get_text(strip="True"), '\n' + 'Size: ' + sizes.get_text(strip="True"), '\n' 'Price: ' + prices.get_text(strip="True"))
previous_content = new_content
if previous_content == new_content:
print("CONTENT NOT CHANGED. | " + str(today))
elif previous_content != new_content:
print("CONTENT CHANGED | " + str(today))
time.sleep(sleeptime)
非常感谢!
【问题讨论】:
-
把这些数据保存到数据库中,然后编写一个程序来检查数据库中是否存在新数据
-
还有监控网站变化的服务
-
您可以订阅网站的RSS提要
标签: python beautifulsoup