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 BeautifulSoupimport pandas as pdimport 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都在同一行中,并且将被刮擦在一起,这可能会使某些人感到困惑,但是我的建议是先刮擦然后再解决问题。 因此,让我们尝试执行此操作。

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)

DONE. Let’s check our dataframe

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

df.head()

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)

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()

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.taodudu.cc/news/show-997610.html

相关文章:

  • 如何不认识自己
  • plotly python_使用Plotly for Python时的基本思路
  • java项目经验行业_行业研究以及如何炫耀您的项目
  • 数据科学 python_适用于数据科学的Python vs(和)R
  • r怎么对两组数据统计检验_数据科学中最常用的统计检验是什么
  • 深度学习概述_深度感测框架概述
  • 为什么即使在班级均衡的情况下,准确度仍然令人困扰
  • 接受拒绝算法_通过算法拒绝大学学位
  • 为什么用scrum_为什么Scrum糟糕于数据科学
  • 使用集合映射和关联关系映射_使用R进行基因ID映射
  • 详尽kmp_详尽的分步指南,用于数据准备
  • SMSSMS垃圾邮件检测器的专业攻击
  • 使用Python进行地理编码和反向地理编码
  • grafana 创建仪表盘_创建仪表盘前要问的三个问题
  • 大数据对社交媒体的影响_数据如何影响媒体,广告和娱乐职业
  • python 装饰器装饰类_5分钟的Python装饰器指南
  • 机器学习实际应用_机器学习的实际好处是什么?
  • mysql 时间推移_随着时间的推移可视化COVID-19新案例
  • 海量数据寻找最频繁的数据_寻找数据科学家的“原因”
  • kaggle比赛数据_表格数据二进制分类:来自5个Kaggle比赛的所有技巧和窍门
  • netflix_Netflix的Polynote
  • 气流与路易吉,阿戈,MLFlow,KubeFlow
  • 顶级数据恢复_顶级R数据科学图书馆
  • 大数据 notebook_Dockerless Notebook:数据科学期待已久的未来
  • 微软大数据_我对Microsoft的数据科学采访
  • 如何击败腾讯_击败股市
  • 如何将Jupyter Notebook连接到远程Spark集群并每天运行Spark作业?
  • twitter 数据集处理_Twitter数据清理和数据科学预处理
  • 使用管道符组合使用命令_如何使用管道的魔力
  • 2020年十大币预测_2020年十大商业智能工具

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

  1. github创建静态页面_如何在10分钟内使用GitHub Pages创建免费的静态站点

    github创建静态页面 Static sites have become all the rage, and with good reason – they are blazingly fast a ...

  2. javascript创建类_如何在10分钟内使用JavaScript创建费用管理器

    javascript创建类 by Per Harald Borgen 通过Per Harald Borgen 如何在10分钟内使用JavaScript创建费用管理器 (How to create an ...

  3. 服务器创建多个dhcp服务_如何在15分钟内创建无服务器服务

    服务器创建多个dhcp服务 by Charlee Li 通过李李 如何在15分钟内创建无服务器服务 (How to create a serverless service in 15 minutes) ...

  4. 首席技术执行官_如何在几分钟内找到任何首席执行官的电子邮件地址

    首席技术执行官 by Theo Strauss 由西奥·斯特劳斯(Theo Strauss) 如何在几分钟内找到任何首席执行官的电子邮件地址 (How to find any CEO's email ...

  5. 如何在开源社区贡献代码_如何在15分钟内从浏览器获得您的第一个开源贡献

    如何在开源社区贡献代码 Matt Mullenweg, founder of Automattic, recently offered this advice to aspiring develope ...

  6. 机器人坐标系建立_如何在30分钟内建立一个简单的搜索机器人

    机器人坐标系建立 by Quinn Langille 奎因·兰吉尔(Quinn Langille) 如何在30分钟内建立一个简单的搜索机器人 (How to Build A Simple Search ...

  7. gitlab定期备份_如何在一分钟内让GitLab为您做定期工作

    gitlab定期备份 by Moe Ibrahim 通过易卜拉欣(Moe Ibrahim) 如何在一分钟内让GitLab为您做定期工作 (How to get GitLab to do periodi ...

  8. es6 ... 添加属性_如何在10分钟内免费将HTTPS添加到您的网站,以及为什么您现在不止需要这样做......

    es6 ... 添加属性 by Ayo Isaiah 通过Ayo Isaiah 如何在10分钟内免费将HTTPS添加到您的网站,以及为什么现在比以往更需要这样做 (How to add HTTPS t ...

  9. 无国界医生_如何在5分钟内创建无国界风格的技能树

    无国界医生 Growing up, I spent my spare time doing what most programmers did: played video games every wa ...

最新文章

  1. 超越RetinaFace,腾讯优图 ASFD 已在 WIDER FACE 霸榜半年!
  2. 寒假训练,2.25,J-Palindrome Names (回文
  3. 容器 - concurrent包之ConcurrentHashMap
  4. 微服务架构如何保障双11狂欢下的99.99%高可用
  5. Python学习笔记:网络编程
  6. leetcode_median of two sorted arrays
  7. 每个程序员都必读的12篇文章
  8. Linux编程 8 (挂载mount,查看磁盘df du,搜索grep,压缩zgip,归档tar)
  9. C#中如何复制窗体到另一个项目
  10. 1Android系统移植与驱动开发概述
  11. java long to float_为什么Java中long可以自动转换成float
  12. mysql char类型c 映射_使用Hibernate原生SQL映射MYSQL的CHAR(n)类型到String时出错
  13. tcp程序——回声客户端
  14. vs2010 sp1 安装错误,重新安装错误
  15. 跟父亲一样伟大的程序员,请照顾好自己!
  16. 从阿里巴巴icon引入图标到微信小程序(可以改变大小,颜色)
  17. Kubernetes Pod Eviction 简介
  18. Ethernet协议
  19. 压缩比13为什么建议用92的油_马自达为啥能在13:1高压缩比下仍然使用92汽油
  20. 2022年武汉东湖新技术开发区知识产权专项资助补贴38项

热门文章

  1. select的一些问题。
  2. springmvc常用注解之@Controller和@RequestMapping
  3. 详解 Spotlight on MySQL监控MySQL服务器
  4. 解决Warning: Cannot modify header information - headers already sent b...
  5. IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
  6. 小猿圈web前端之网站性能优化方案
  7. 朱晔和你聊Spring系列S1E3:Spring咖啡罐里的豆子
  8. [转]在ROS下使用zeroconf配置多机通信
  9. commons-pool
  10. MySQL安装与设置