Добрый день, первая функция отпрбатывает замечательно, все что на странице находит парсит и добавляет в json файл. Но когда запускаешь вторую функцию он либо ни чего не передает и завершает скрипт либо добавляет 1 блок но он даже не последнее что появилось, а какой то старый блок. Подскажите пожалуйста что может быть?
from email.mime import application
import json
from textwrap import indent
from selenium import webdriver
import config
import telebot
from telebot import types
import time
import requests
import re
import requests
from bs4 import BeautifulSoup as bs
def get_first_leads():
leads = "n.php"
url = config.URL + leads
driver = webdriver.Firefox()
driver.get(url)
login = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/div/div/div[1]/label/span/input')
login.send_keys(config.LOGIN)
time.sleep(0.1)
passw = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/div/div/div[2]/label/span/input')
passw.send_keys(config.PASSWORD)
click = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/a')
click.click()
time.sleep(15)
page = driver.page_source
soup = bs(page, 'lxml')
applications_cards = soup.find_all(class_=re.compile("OrderSnippetContainerStyles__Container"))
new_applcations = {}
for application in applications_cards:
if application.find('h3', class_=re.compile("SubjectAndPriceStyles")):
application_title = application.find('h3', class_=re.compile("SubjectAndPriceStyles")).text.strip()
else:
application_title = "Нет заголовка"
if application.find('p', class_=re.compile("SnippetBodyStyles__MainInfo")):
application_snippet = application.find('p', class_=re.compile("SnippetBodyStyles__MainInfo")).text.strip()
else:
application_snippet = "Нет описания"
if application.find('span', class_=re.compile("LocationAndScheduleStyles__TextContainer")):
application_location = application.find('span', class_=re.compile("LocationAndScheduleStyles__TextContainer")).text.strip()
else:
application_location = "нет местоположения"
if application.find('span', class_=re.compile("LocationAndScheduleStyles__ScheduleText")):
application_shedule = application.find('span', class_=re.compile("LocationAndScheduleStyles__ScheduleText")).text.strip()
else:
application_shedule= "Свободная дата"
application_name_client = application.find('span', class_=re.compile("StatusAndClientInfoStyles__Name")).text.strip()
application_link_req = application.find('a', class_=re.compile("SnippetBodyStyles__Container"))
application_link = application_link_req.get('href')
application_id = application_link_req.get('id')
new_applcations [application_id] = {
"application_title":application_title,
"application_snippet":application_snippet,
"application_location":application_location,
"application_shedule":application_shedule,
"application_name_client":application_name_client,
"application_link":url + application_link,
"application_id":application_id
}
with open ("new_applications.json", "w") as file:
json.dump(new_applcations, file, indent =4, ensure_ascii=False)
def check_application_updater ():
with open ("new_applications.json") as file:
new_applications= json.load(file)
leads = "n.php"
url = config.URL + leads
driver = webdriver.Firefox()
driver.get(url)
login = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/div/div/div[1]/label/span/input')
login.send_keys(config.LOGIN)
time.sleep(0.1)
passw = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/div/div/div[2]/label/span/input')
passw.send_keys(config.PASSWORD)
click = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/a')
click.click()
time.sleep(15)
page = driver.page_source
soup = bs(page, 'html.parser')
applications_cards = soup.find_all(class_=re.compile("OrderSnippetContainerStyles__Container"))
fresh_applications = {}
while True:
for application in applications_cards:
application_link_req = application.find('a', class_=re.compile("SnippetBodyStyles__Container"))
application_link = application_link_req.get('href')
application_id = application_link_req.get('id')
if application_id in new_applications:
continue
else:
for application in applications_cards:
if application.find('h3', class_=re.compile("SubjectAndPriceStyles")):
application_title = application.find('h3', class_=re.compile("SubjectAndPriceStyles")).text.strip()
else:
application_title = "Нет заголовка"
if application.find('p', class_=re.compile("SnippetBodyStyles__MainInfo")):
application_snippet = application.find('p', class_=re.compile("SnippetBodyStyles__MainInfo")).text.strip()
else:
application_snippet = "Нет описания"
if application.find('span', class_=re.compile("SnippetBodyStyles__MainInfo")):
application_location = application.find('span', class_=re.compile("SnippetBodyStyles__MainInfo")).text.strip()
else:
application_location = "нет местоположения"
if application.find('span', class_=re.compile("LocationAndScheduleStyles__ScheduleText")):
application_shedule = application.find('span', class_=re.compile("LocationAndScheduleStyles__ScheduleText")).text.strip()
else:
application_shedule= "Свободная дата"
application_name_client = application.find('span', class_=re.compile("StatusAndClientInfoStyles__Name")).text.strip()
# application_link_req = application.find('a', class_=re.compile("SnippetBodyStyles__Container"))
# application_link = application_link_req.get('href')
# application_id = application_link_req.get('id')
new_applications [application_id] = {
"application_title":application_title,
"application_snippet":application_snippet,
"application_location":application_location,
"application_shedule":application_shedule,
"application_name_client":application_name_client,
"application_link":url + application_link,
"application_id":application_id
}
fresh_applications [application_id] = {
"application_title":application_title,
"application_snippet":application_snippet,
"application_location":application_location,
"application_shedule":application_shedule,
"application_name_client":application_name_client,
"application_link":url + application_link,
"application_id":application_id
}
with open ("new_applications.json", "w") as file:
json.dump(new_applications, file, indent =4, ensure_ascii=False)
return fresh_applications
time.sleep(60)
def main():
#get_first_leads()
print(check_application_updater())
if __name__ == '__main__':
main()