0

I try to parse page ozon.ru

And I have some problem. I should scroll the page and next get all html code. But I scroll page, the height is changing, but results of parsing is wrong, because it returns result only from first page. I can't understand, I should update html code of page and how can I do that?

def get_link_product_ozon(url):
    chromedriver = "chromedriver"
    os.environ["webdriver.chrome.driver"] = chromedriver
    driver = webdriver.Chrome(chromedriver)
    driver.get(url)
    i = 0
    last_height = driver.execute_script("return document.body.scrollHeight")
    while i < 80:
        try:
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            time.sleep(3)
            new_height = driver.execute_script("return document.body.scrollHeight")
            i += 1
            last_height = new_height
        except:
            time.sleep(3)
            continue
    soup = BeautifulSoup(driver.page_source, "lxml")
    all_links = soup.findAll('div', class_='bOneTile inline jsUpdateLink mRuble ')
    for link in all_links:
        print(link.attrs['data-href'])

    driver.close()

1 Answer 1

1

Those divs loaded after scrolling don't have class mRuble and you are doing exact string matching. Maybe try something like:

all_links = soup.select('div.bOneTile.inline.jsUpdateLink')
all_links = soup.select('div[data-href]')
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.