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.pswp.cn/news/392385.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392385.shtml
英文地址,請注明出處:http://en.pswp.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…