Код: Выделить всё
from multiprocessing.connection import Client
from playwright.sync_api import sync_playwright
from bs4 import BeautifulSoup
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from bson import ObjectId
Import Time
price1 = 0
price12 = 0
price_state1 = 0
price_state2 = 0
num = 0
While True:
def run_playwright_test():
with sync_playwright() as p:
# Launch the browser (headless=False to see the browser)
browser = p.firefox.launch(headless = False)
Context = browser.new_context()
Context.set_default_timeout (0)
Page = Context.new_page()
Global price1
Global price2
Global price_state1
Global price_state2
page.goto('https://rivalregions.com/#overview')
page.fill('input[name="mail"]', 'password)
page.fill('input[name="p"]', 'password)
page.click('input[name="s"]')
# oil market
page.locator('div[action="storage"].item_menu.storage_menu.ajax_action.header_menu_item.tc').click();
page.click('div.tip.float_left.white.imp.storage_item.pointer.hov.ib_border');
# oil
page.wait_for_selector('div.storage_price')
html_content = Page.Content()
soup = BeautifulSoup(html_content, 'html.parser')
price_span1 = soup.find('div', class_='storage_price').find('span', class_='dot')
if price_span1:
price_1 = price_span1.get_text(strip = True)
price_1 = price_1.replace('$', '').replace(' ', '') # Remove '$' and spaces
price_1 = price_1.replace('.', '') # Remove '$' and spaces
price_1 = float(price_1) # Convert to a numeric value (float)
print(f"Extracted price: {price_1}")
Else:
Print ("Price not found")
# ore market
page.locator('div[action="storage"].item_menu.storage_menu.ajax_action.header_menu_item.tc').click();
page.click('div.storage_number span[url="4"]')
# ore
page.wait_for_selector('div.storage_price')
Time.sleep (10)
html_content = Page.Content()
soup = BeautifulSoup(html_content, 'html.parser')
price_span2 = soup.find('div', class_='storage_price').find('span', class_='dot')
if price_span2:
price_2 = price_span2.get_text(strip = True)
price_2 = price_2.replace('$', '').replace(' ', '') # Remove '$' and spaces
price_2 = price_2.replace('.', '') # Remove '$' and spaces
price_2 = float(price_2)
print(f"Extracted price: {price_2}")
Else:
Print ("Price not found")
Приведенный выше код — это лишь малая часть, он выполняет гораздо больше чаще всего не получается или пропускается строка перед:
Код: Выделить всё
page.wait_for_selector('div.storage_price')Если таковой имеется можете сказать мне, почему это происходит и как это исправить, и это будет здорово.
Подробнее здесь: https://stackoverflow.com/questions/793 ... out-errors
Мобильная версия