scrape创建_确实在2分钟内对Scrape公司进行了评论和评分

scrape创建

网页搜罗,数据科学 (Web Scraping, Data Science)

In this tutorial, I will show you how to perform web scraping using Anaconda Jupyter notebook and the BeautifulSoup library.

在本教程中,我将向您展示如何使用Anaconda Jupyter笔记本和BeautifulSoup库执行Web抓取。

We’ll be scraping Company reviews and ratings from Indeed platform, and then we will export them to Pandas library dataframe and then to a .CSV file.

我们将从Indeed平台上抓取公司的评论和评分,然后将它们导出到Pandas库数据框,然后导出到.CSV文件。

Let us get straight down to business, however, if you’re looking on a guide to understanding Web Scraping in general, I advise you of reading this article from Dataquest.

但是,让我们直接从事业务,但是,如果您正在寻找一般理解Web爬网的指南,建议您阅读Dataquest的这篇文章。

Let us start by importing our 3 libraries

让我们从导入3个库开始

from bs4 import BeautifulSoup
import pandas as pd
import requests

Then, let’s go to indeed website and examine which information we want, we will be targeting Ernst & Young firm page, you can check it from the following link

然后,让我们转到确实的网站并检查我们想要的信息,我们将以安永会计师事务所为目标页面,您可以从以下链接中进行检查

https://www.indeed.com/cmp/Ey/reviews?fcountry=IT

Based on my location, the country is indicated as Italy but you can choose and control that if you want.

根据我的位置,该国家/地区显示为意大利,但您可以根据需要选择和控制该国家/地区。

In the next picture, we can see the multiple information that we can tackle and scrape:

在下一张图片中,我们可以看到我们可以解决和抓取的多种信息:

1- Review Title

1-评论标题

2- Review Body

2-审查机构

3- Rating

3-评分

4- The role of the reviewer

4-审稿人的角色

5- The location of the reviewer

5-评论者的位置

6- The review date

6-审查日期

However, you can notice that Points 4,5&6 are all in one line and will be scraped together, this can cause a bit of confusion for some people, but my advice is to scrape first then solve problems later. So, let’s try to do this.

但是,您会注意到,点4,5&6都在同一行中,并且将被刮擦在一起,这可能会使某些人感到困惑,但是我的建议是先刮擦然后再解决问题。 因此,让我们尝试执行此操作。

Image for post

After knowing what we want to scrape, we need to find out how much do we need to scrape, do we want only 1 review? 1 page of reviews or all pages of reviews? I guess the answer should be all pages!!

知道要抓取的内容后,我们需要找出需要抓取的数量,我们只需要进行1次审核吗? 1页评论或所有页面评论? 我想答案应该是所有页面!

If you scrolled down the page and went over to page 2 you will find that the link for that page became as following:

如果您向下滚动页面并转到页面2,则会发现该页面的链接如下:

https://www.indeed.com/cmp/Ey/reviews?fcountry=IT&start=20

Then try to go to page 3, you will find the link became as following:

然后尝试转到第3页,您会发现链接如下所示:

https://www.indeed.com/cmp/Ey/reviews?fcountry=IT&start=4

Looks like we have a pattern here, page 2=20 , page 3 = 40, then page 4 = 60, right? All untill page 8 = 140

看起来我们这里有一个模式,第2页= 20,第3页= 40,然后第4页= 60,对吗? 全部直到第8页= 140

Let’s get back to coding, start by defining your dataframe that you want.

让我们回到编码,首先定义所需的数据框。

df = pd.DataFrame({‘review_title’: [],’review’:[],’author’:[],’rating’:[]})

In the next code I will make a for loop that starts from 0, jumps 20 and stops at 140.

在下一个代码中,我将创建一个for循环,该循环从0开始,跳20,然后在140处停止。

1- Inside that for loop we will make a GET request to the web server, which will download the HTML contents of a given web page for us.

1-在该for循环内,我们将向Web服务器发出GET请求,该服务器将为我们下载给定网页HTML内容。

2- Then, We will use the BeautifulSoup library to parse this page, and extract the text from it. We first have to create an instance of the BeautifulSoup class to parse our document

2-然后,我们将使用BeautifulSoup库解析此页面,并从中提取文本。 我们首先必须创建BeautifulSoup类的实例来解析我们的文档

3- Then by inspecting the html, we choose the classes from the web page, classes are used when scraping to specify specific elements we want to scrape.

3-然后通过检查html,我们从网页上选择类,在抓取时使用这些类来指定要抓取的特定元素。

4- And then we can conclude by adding the results to our DataFrame created before.

4-然后我们可以通过将结果添加到之前创建的DataFrame中来得出结论。

“I added a picture down for how the code should be in case you copied and some spaces were added wrong”

“我在图片上添加了图片,以防万一您复制了代码并添加了错误的空格,应该如何处理”

for i in range(10,140,20):
url = (f’https://www.indeed.com/cmp/Ey/reviews?fcountry=IT&start={i}')
header = {“User-Agent”:”Mozilla/5.0 Gecko/20100101 Firefox/33.0 GoogleChrome/10.0"}
page = requests.get(url,headers = header)
soup = BeautifulSoup(page.content, ‘lxml’)
results = soup.find(“div”, { “id” : ‘cmp-container’})
elems = results.find_all(class_=’cmp-Review-container’)
for elem in elems:
title = elem.find(attrs = {‘class’:’cmp-Review-title’})
review = elem.find(‘div’, {‘class’: ‘cmp-Review-text’})
author = elem.find(attrs = {‘class’:’cmp-Review-author’})
rating = elem.find(attrs = {‘class’:’cmp-ReviewRating-text’})
df = df.append({‘review_title’: title.text,
‘review’: review.text,
‘author’: author.text,
‘rating’: rating.text
}, ignore_index=True)
Image for post

DONE. Let’s check our dataframe

完成。 让我们检查一下数据框

df.head()
Image for post

Now, once scraped, let’s try solve the problem we have.

现在,一旦刮掉,让我们尝试解决我们遇到的问题。

Notice the author coulmn had 3 differnt information seperated by (-)

请注意,作者可能有3个不同的信息,并以(-)分隔

So, let’s split them

所以,让我们分开

author = df[‘author’].str.split(‘-’, expand=True)
Image for post

Now, let’s rename the columns and delete the last one.

现在,让我们重命名列并删除最后一列。

author = author.rename(columns={0: “job”, 1: “location”,2:’time’})del author[3]

Then let’s join those new columns to our original dataframe and delete the old author column

然后,将这些新列添加到原始数据框中,并删除旧的author列

df1 = pd.concat([df,author],axis=1)
del df1[‘author’]

let’s examine our new dataframe

让我们检查一下新的数据框

df1.head()
Image for post

Let’s re-organize the columns and remove any duplicates

让我们重新整理各列并删除所有重复项

df1 = df1[[‘job’, ‘review_title’, ‘review’, ‘rating’,’location’,’time’]]
df1 = df1.drop_duplicates()

Then finally let’s save the dataframe to a CSV file

最后,让我们将数据框保存到CSV文件中

df1.to_csv(‘EY_indeed.csv’)

You should now have a good understanding of how to scrape and extract data from Indeed. A good next step for you if you are familiar a bit with web scraping it to pick a site and try some web scraping on your own.

您现在应该对如何从Indeed抓取和提取数据有很好的了解。 如果您对网络抓取有点熟悉,可以选择一个不错的下一步来选择一个站点,然后自己尝试一些网络抓取。

Happy Coding:)

快乐编码:)

翻译自: https://towardsdatascience.com/scrape-company-reviews-ratings-from-indeed-in-2-minutes-59205222d3ae

scrape创建

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392385.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ArcGIS自定义高程

没写呢。 转载于:https://www.cnblogs.com/jiangyuanjia/p/11220183.html

Java基础——String类(一)

一、String 类代表字符串 Java 程序中的所有字符串字面值(如 "abc" )都作为此类的实例实现。 字符串是常量;它们的值在创建之后不能更改。字符串缓冲区支持可变的字符串。因为 String 对象是不可变的,所以可以共享。例如…

java jol原理_Java对象布局(JOL)实现过程解析

java对象布局JOL(java object layout),描述对象在堆内存的布局。如下图:1.markword 固定长度8byte,描述对象的identityhashcode,分代年龄,锁信息等(https://www.jb51.net/article/183984.htm);2.klasspoint 固定长度4b…

数据库维护相关

(1)SQL Server 查看数据表使用空间 exec sp_spaceused 表名 (2)SQL Server 数据表使用空间排序 exec sp_MSForeachTable precommandN create table ##( table_name sysname, records int, save_space Nvarchar(10), use_space var…

Redux初学者指南

by Safeer Hayat通过更安全的哈亚特 Understanding Redux as a beginner can be quite confusing. Redux has an abundance of new terms and concepts which are often pretty unintuitive. This guide presents a very simplified example of a Redux implementation. I wil…

leetcode 86. 分隔链表(链表)

给你一个链表和一个特定值 x ,请你对链表进行分隔,使得所有小于 x 的节点都出现在大于或等于 x 的节点之前。 你应当保留两个分区中每个节点的初始相对位置。 示例: 输入:head 1->4->3->2->5->2, x 3 输出&am…

极光推送

推送原理 IOS 通过APNs推送服务。 每个设备只要保持一个与APNs的常链接,服务器将要推送的消息发送给APNs,APNs再将消息转发到响应的手机,手机内置的程序再进行分发,到响应的APP,就能很好的实现推送功能 Andriod 虽然谷…

电脑通过手机上网的方法

(适用于包月CMWAP无限流量服务,只收CMWAP费用)移动手机(GPRS) CMWAP无限流量包月服务,可以通过手机作调制解调器,将手机和电脑连接用代理服务器上网. 看到了很多帖子,整理了一下,把它贴出来供大家参考。一 该方法对手机要求:1 手…

java入门学习_Java入门学习进阶知识点

Java入门学习进阶知识点入门阶段,主要是培养Java语言的编程思想。了解Java语言的语法,书写规范等,掌握Eclipse、MyEclipse等开发工具,编写Java代码的能力。学完这个阶段你应该可进行小型应用程序开发并且可以对数据库进行基本的增…

如何不认识自己

重点 (Top highlight)By Angela Xiao Wu, assistant professor at New York University纽约大学助理教授Angela Xiao Wu This blog post comes out of a paper by Angela Xiao Wu and Harsh Taneja that offers a new take on social sciences’ ongoing embrace of platform …

JDBC 数据库连接操作——实习第三天

今天开始了比较重量级的学习了,之前都是对于Java基础的学习和回顾。继续上篇的话题,《谁动了我的奶酪》,奉献一句我觉得比较有哲理的话:“学会自嘲了,而当人们学会自嘲,能够嘲笑自己的愚蠢和所做的错事时,他就在开始改变了。他甚至…

webassembly_WebAssembly的设计

webassemblyby Patrick Ferris帕特里克费里斯(Patrick Ferris) WebAssembly的设计 (The Design of WebAssembly) I love the web. It is a modern-day superpower for the dissemination of information and empowerment of the individual. Of course, it has its downsides …

leetcode 509. 斐波那契数(dfs)

斐波那契数,通常用 F(n) 表示,形成的序列称为 斐波那契数列 。该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和。也就是: F(0) 0,F(1) 1 F(n) F(n - 1) F(n - 2),其中 n > 1 给你 n &a…

java基本特性_Java面试总结之Java基础

无论是工作多年的高级开发人员还是刚入职场的新人,在换工作面试的过程中,Java基础是必不可少的面试题之一。能不能顺利通过面试,拿到自己理想的offer,在准备面试的过程中,Java基础也是很关键的。对于工作多年的开发人员…

plotly python_使用Plotly for Python时的基本思路

plotly pythonI recently worked with Plotly for data visualization on predicted outputs coming from a Machine Learning Model.我最近与Plotly合作,对来自机器学习模型的预测输出进行数据可视化。 The documentation I referred to : https://plotly.com/pyt…

转发:毕业前的赠言

1、找一份真正感兴趣的工作。 “一个人如果有两个爱好,并且把其中一个变成自己的工作,那会是一件非常幸福的事情。那么另外一个爱好用来做什么?打发时间啦。所以,第二个兴趣非常重要,在你无聊寂寞的时候越发显得它…

Python模块之hashlib:提供hash算法

算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等。 什么是摘要算法呢?摘要算法又称哈希算法、散列算法。它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示&#xf…

css flexbox模型_完整CSS课程-包括flexbox和CSS网格

css flexbox模型Learn CSS in this complete 83-part course for beginners. Cascading Style Sheets (CSS) tell the browser how to display the text and other content that you write in HTML.在这本由83部分组成的完整课程中,为初学者学习CSS。 级联样式表(CS…

leetcode 830. 较大分组的位置

在一个由小写字母构成的字符串 s 中,包含由一些连续的相同字符所构成的分组。 例如,在字符串 s “abbxxxxzyy” 中,就含有 “a”, “bb”, “xxxx”, “z” 和 “yy” 这样的一些分组。 分组可以用区间 [start, end] 表示,其中…

php 匹配图片路径_php正则匹配图片路径原理与方法

下面我来给大家介绍在php正则匹配图片路径原理与实现方法,有需要了解的朋友可进入参考参考。提取src里面的图片地址还不足够,因为不能保证那个地址一定是绝对地址,完全的地址,如果那是相对的呢?如果地址诸如&#xff1…