我有一個關于從 Indeed for Meta 中抓取員工評論的問題。我只是在看美國員工的評論,確實網站顯示有467條來自美國員工的評論,如下圖,但我從網路爬取中獲得了490條評論。為什么網路抓取的評論比網站上顯示的評論多?我該如何解決這個問題?
這是鏈接:

# Load the Modules
from bs4 import BeautifulSoup
import pandas as pd
import requests
import numpy as np
import pandas as pd
lst=[]
for i in range(0, 480, 20):
print(i)
url = (f'https://www.indeed.com/cmp/Meta-dd1502f2/reviews?start={i}')
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"}
page = requests.get(url, headers = header)
soup = BeautifulSoup(page.content, 'lxml')
main_data = soup.find_all("div",attrs={"data-tn-section":"reviews"})
for data in main_data:
try:
date=data.find("span",attrs={"itemprop":"author"}).get_text(strip=True).split("-")[2]
except AttributeError:
date=np.nan
try:
title=data.find("h2").get_text(strip=True)
except AttributeError:
title=np.nan
try:
status=data.find("span",attrs={"itemprop":"author"}).get_text(strip=True).split("-")[0]
except AttributeError:
status=np.nan
try:
location=data.find("span",attrs={"itemprop":"author"}).get_text(strip=True).split("-")[1]
except AttributeError:
location=np.nan
try:
review=data.find("span",attrs={"itemprop":"reviewBody"}).get_text(strip=True)
except AttributeError:
review=np.nan
try:
pros=data.find('h2',class_='css-6pbru9 e1tiznh50').next_sibling.get_text(strip=True)
except:
pros=np.nan
try:
cons=data.find('h2',class_='css-cvf89l e1tiznh50').next_sibling.get_text(strip=True)
except:
cons=np.nan
try:
rating=data.find("div",attrs={"itemprop":"reviewRating"}).find("button")['aria-label'].split(" ")[0]
except AttributeError:
rating=np.nan
lst.append([date, title, status, location, review, pros, cons, rating])
df_meta=pd.DataFrame(data=lst,columns=['date', 'title', 'status', 'location', 'review', 'pros', 'cons', 'rating'])
df_meta

uj5u.com熱心網友回復:
Indeed 在每頁上回傳 21 個結果。您的分頁假設頁面上有 20 個結果。
但是,頁數 (24) 似乎表明每頁有 20 個結果。
20 * 23 7 (on the last page) = 467
實際發生的是每個頁面回傳 21 個結果:
21 * 23 7 = 490
這給了你的號碼。
看起來確實有一個錯誤,即回傳錯誤數量的評論,然后您按日期訂購。當基于評級訂購時,我沒有看到同樣的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422153.html
標籤:
