用硒刮玻璃门网



我正在尝试抓取下面链接左下角图表中显示的评级趋势数据,但似乎无法找到获取它的方法。我担心这是因为它被嵌入为图片,因此无法访问数据,但我想我会检查一下。

添加了我缝合在一起的代码,但我只得到轴值。

如有任何帮助,我们将不胜感激。

https://www.glassdoor.com/Reviews/Netflix-Reviews-E11891.htm#trends-总体评级

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
import pandas as pd
from selenium.webdriver.common import action_chains, keys
from selenium.common.exceptions import NoSuchElementException
import numpy as np
import sys
import re
import warnings
options = Options()
options.headless = True

driver = webdriver.Chrome(r'PATH',options=options)
driver.get('https://www.glassdoor.com/Reviews/Netflix-Reviews-E11891.htm#trends-overallRating')
trend_element = driver.find_elements_by_xpath('//*[@id="DesktopTrendChart"]')[0]
trend = trend_element.text
print(trend)

我最初尝试使用BeautifulSoup。

我能够提取出相应值的所有坐标(我成功地做到了)。花了大约一个小时的时间找到它的位置,提取它,进入一个漂亮、整洁的数据帧。

在下一步中,我将把x和y坐标转换为相应的x和y标签,然后插值以创建一组更细粒度的数据(我还没有尝试过)。我预计这将需要大约一个小时左右的时间

在此之前,我做了更多的研究,在这里发现了一篇有趣的文章。

读完它,然后回到最初的问题,我能够在a)更少的代码行中做到这一点,b)没有BeautifulSoup,c)花了我大约5-10分钟的时间,d)我学到了一些新东西。

所以,仔细阅读这个链接,查看代码,这应该会让你得到你需要的。

import requests
import json
import pandas as pd
url = 'https://www.glassdoor.co.uk/api/employer/11891-rating.htm?dataType=trend&category=overallRating&locationStr=&jobTitleStr=&filterCurrentEmployee=false'
with requests.Session() as se:
se.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
"Accept-Encoding": "gzip, deflate",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "en"
}
response = se.get(url)
data = json.loads(response.text)
results = pd.DataFrame()
results['date'], results['rating'] = data['dates'], data['employerRatings']

输出:

print (results)
date  rating
0   2018/12/30  3.66104
1   2018/12/30  3.66311
2   2018/11/25  3.69785
3   2018/10/28  3.73478
4    2018/9/30  3.68311
5    2018/8/26  3.69093
6    2018/7/29  3.70312
7    2018/6/24  3.74851
8    2018/5/27  3.67543
9    2018/4/29  3.67500
10   2018/3/25  3.62248
11   2018/2/25  3.73467
12   2018/1/28  3.70791
13  2017/12/31  3.72217
14  2017/11/26  3.69733
15  2017/10/29  3.61443
16   2017/9/24  3.47046
17   2017/8/27  3.46511
18   2017/7/30  3.46711
19   2017/6/25  3.48164
20   2017/5/28  3.52925
21   2017/4/30  3.46825
22   2017/3/26  3.46874
23   2017/2/26  3.52620

最新更新