【发布时间】:2020-01-30 19:52:11
【问题描述】:
我正在尝试从https://www.innisfree.com/kr/ko/ProductReviewList.do 中抓取超过 10 页的评论
但是,当我转到下一页并尝试获取新页面的评论时,我仍然只能获得第一页的评论。
我使用了 driver.execute_script("goPage(2)") 和 time.sleep(5) 但我的代码只给了我第一页的评论。
'''我没有使用for循环只是为了查看page1和page2之间的结果是否不同''' '''我导入了beautifulsoup和selenium'''
这是我的代码:
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)
【问题讨论】:
-
任何帮助将非常非常感激。谢谢。
-
你在哪里分配
soup?在你打电话给goPage(2)之后你有没有重新分配汤。哦,请删除多余的空行 -
如果您使用 selenium,只需单击“下一步”按钮?
标签: python selenium web-scraping beautifulsoup web-crawler