我如何获得硒的下一页评论?

问题描述 投票:0回答:1

我正在尝试从https://www.innisfree.com/kr/ko/ProductReviewList.do中抓取10页以上的评论,>

但是,当我移至下一页并尝试获得新页的评论时,我仍然仅获得第一页的评论。

我使用driver.execute_script(“ goPage(2)”)以及time.sleep(5),但我的代码仅给我第一页的评论。

'''我没有使用for循环只是为了查看page1和page2之间的结果是否不同''''''我进口了Beautifulsoup和硒'''

这是我的代码:

  url = "https://www.innisfree.com/kr/ko/ProductReviewList.do"

  chromedriver = r'C:\Users\hhm\Downloads\chromedriver_win32\chromedriver.exe'

  driver = webdriver.Chrome(chromedriver)

  driver.get(url)


  print("this is page 1")

  driver.execute_script("goPage(1)")

  nTypes = soup.select('.reviewList ul .newType div[class^=reviewCon] .reviewConTxt')


  for nType in nTypes:

         product = nType.select_one('.pdtName').text

         print(product)


 print('\n')

 print("this is page 2")

 driver.execute_script("goPage(2)")

 time.sleep(5)

 nTypes = soup.select('.reviewList ul .newType div[class^=reviewCon] .reviewConTxt')


 for nType in nTypes:

         product = nType.select_one('.pdtName').text

         print(product)

我正在尝试从https://www.innisfree.com/kr/ko/ProductReviewList.do抓取10页以上的评论,但是当我移至下一页并尝试获取新页面的评论时,我仍然得到...

python selenium web-scraping beautifulsoup web-crawler
1个回答
0
投票

如果第二页作为新窗口打开,则需要切换到另一页并将硒控件切换到另一窗口

© www.soinside.com 2019 - 2024. All rights reserved.