0
내가 페이지
ozon.ru
을 구문 분석하려고
과 분석 그리고 약간의 문제가 있습니다. 페이지를 스크롤 한 후 모두 html
코드를 가져와야합니다. 그러나 페이지를 스크롤 할 때 높이가 변하지 만 첫 번째 페이지의 결과 만 반환하기 때문에 구문 분석의 결과가 잘못되었습니다. 이해할 수 없으며 페이지의 html 코드를 업데이트해야하며 어떻게해야합니까?
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()