/
harrisson55
/
pythonprojectnba
Обзор
Документация
Войти
/
harrisson55
/
pythonprojectnba
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
main.py
87 строк
3 KB
notebook
Изменение колонок.
20 июл 2024, 15:43
20 июл 2024, 15:43
8ecd1ad
Код
Авторство
О чём код?
import requests import pymssql from datetime import datetime from bs4 import BeautifulSoup SERVER = "80.76.42.208:1433" USER = "user3" PASSWORD = "Rom@wka55" DATABASE = "NbaDashoboard" connection = pymssql.connect(server=SERVER, user=USER, password=PASSWORD, database=DATABASE) pymssql.connect() cursor = connection.cursor() cursor.execute("SELECT * FROM dbo.TestTable") name_team = input("Введите название команды: ") previously_extracted_links_2 = ['https://www.sports.ru/basketball/club/'+name_team+'/calendar/'] links_massive1 = [] links_massive2 = [] links_massive3 = [] links_massive4 = [] symbols_to_remove = ["/n","Дата","'dot',","\xa0"] today = datetime.today() print(today) for url in previously_extracted_links_2: response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.content, 'html.parser') symbols_to_remove = ["\n"] links = soup.find_all('td', 'name-td alLeft' in 'class') links_massive = [] for link in links: if ':' in link.get_text() and '|' not in link.get_text(): links_massive1.append(link.get_text()) print(links_massive1) for url in previously_extracted_links_2: response = requests.get(url) if response.status_code == 200: soup1 = BeautifulSoup(response.content, 'html.parser') symbols_to_remove2 = "Дата" links2 = soup1.find_all('td', class_='name-td alLeft bordR') links_massive2 = [] for link2 in links2: if symbols_to_remove2 not in link2.get_text(): links_massive2.append(link2.get_text()) print(links_massive2) for url in previously_extracted_links_2: response = requests.get(url) if response.status_code == 200: soup3 = BeautifulSoup(response.content, 'html.parser') name_tds = soup3.find_all('td', class_='name-td') teams = [td.find('a').get_text(strip=True) for td in name_tds if td.find('a') ] evert_thrid_team = teams[2::3] for team in evert_thrid_team: links_massive3.append(team) print(links_massive3) for url in previously_extracted_links_2: response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.content, 'html.parser') symbols_to_remove4 = "\xa0" links = soup.find_all('td', class_= ['alRight padR20'] ) for link4 in links: if symbols_to_remove4 not in link4.get_text(): links_massive4.append(link4.get_text()) print(links_massive4) for i in range(len(links_massive1)): links_massive1[i] = "".join([char for char in links_massive1[i] if char not in symbols_to_remove]) links_massive2[i] = "".join([char for char in links_massive2[i] if char not in symbols_to_remove]) links_massive4[i] = "".join([char for char in links_massive4[i] if char not in symbols_to_remove]) sql_query = f"INSERT INTO dbo.TestTable (calendar_date,enemy,score,team,upload_date,home) VALUES ('{links_massive2[i]}',N'{links_massive3[i]}','{links_massive1[i]}','{name_team}','{today}',N'{links_massive4[i]}')" cursor.execute(sql_query) connection.commit() connection.close()