网页搜罗评论-Flipkart

时间:2018-09-24 18:35:12

标签: python-3.x web-scraping beautifulsoup python-requests selenium-chromedriver

我正在尝试取出产品的全部评论(点击更多阅读后会显示评论的剩余一半。但是我仍然无法这样做。它没有显示评论的全部内容,因此会消失单击“更多”选项后,下面是代码,单击“更多”选项,还可以从网站获取数据

import requests
from bs4 import BeautifulSoup
from selenium import webdriver

response = requests.get("https://www.flipkart.com/poco-f1-graphite-black-64-gb/product-reviews/itmf8fyjyssnt25c?page=2&pid=MOBF85V7A6PXETAX")    
data = BeautifulSoup(response.content, 'lxml')
chromepath = r"C:\Users\Mohammed\Downloads\chromedriver.exe"
driver=webdriver.Chrome(chromepath)
driver.get("https://www.flipkart.com/poco-f1-graphite-black-64-gb/product-reviews/itmf8fyjyssnt25c?page=2&pid=MOBF85V7A6PXETAX")
d = driver.find_element_by_class_name("_1EPkIx")
d.click()
title = data.find_all("p",{"class" : "_2xg6Ul"})
text1 = data.find_all("div",{"class" : "qwjRop"})
name = data.find_all("p",{"class" : "_3LYOAd _3sxSiS"})
for t2, t , t1 in zip(title,text1,name) :
    print(t2.text,'\n',t.text,'\n',t1.text)

1 个答案:

答案 0 :(得分:0)

要获得完整的评论,必须单击那些bob_coin_priv.ecdh(alice_coin_priv.public_key.public_key)== alice_coin_priv.ecdh(bob_coin_priv.public_key.public_key) 按钮以展开其余部分。正如您已经将READ MOREselenium结合使用一样,我已经修改了脚本以遵循逻辑。该脚本将首先单击那些BeautifulSoup按钮。完成后,它将从那里解析所有READ MOREtitles。您现在可以从多页(最多4页)中获取reviewstitles

reviews