option = webdriver.ChromeOptions() browser = webdriver.Chrome(options = option)…
- User
option = webdriver.ChromeOptions() browser = webdriver.Chrome(options = option) browser.get('https://mathsolver.microsoft.com/ru/solve-problem/x^2-5x=6') html = browser.page_source print(html) в html есть такие элементы Чтобы решить уравнение, разложите x^{2}-5x-6 на множители по формуле x^{2}+\left(a+b\right)x+ab=\left(x+a\right)\left(x+b\right). Чтобы найти a и b, настройте систему для решения. Мне надо получить выражения Чтобы решить уравнение, разложите x^{2}-5x-6 на множители по формуле x^{2}+\left(a+b\right)x+ab=\left(x+a\right)\left(x+b\right). Чтобы найти a и b, настройте систему для решения.
- Assistant
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser') element = soup.find('div', class_='Step_stepPreviewContent__scxab')
if element: print(element.text) else: print("Element not found")
- User
- Assistant
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser') element = soup.find('div', class_='Steps_solutionSteps__a7lQq')
if element: children = element.find_all() for child in children: print(f"Element: {child.name}, Class: {child.get('class')}") else: print("Element not found")
- User
а если я хочу в element найти только Steps_sectionTitle__WYFvr steps-title
- Assistant
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser') element = soup.find('div', class_='Steps_solutionSteps__a7lQq')
if element: specific_element = element.find('div', class_='Steps_sectionTitle__WYFvr steps-title') if specific_element: print(f"Element found: {specific_element.text}") else: print("Specific element not found") else: print("Element not found")
- User
- Assistant
import re
Find the script tag with id NEXT_DATA
script_tags = soup.find_all('script') next_data = None for script_tag in script_tags: if script_tag.get('id') == 'NEXT_DATA': next_data = script_tag.text break
if next_data: match = re.search(r'({"props":{.*})', next_data) if match: data = match.group(1) print(data) else: print("Data not found in script tag") else: print("Script tag with id NEXT_DATA not found")