
עם תנופת המסחר האלקטרוני, עסקים נכנסו לאינטרנט. גם לקוחות מחפשים מוצרים באינטרנט. שלא כמו השוק הלא מקוון, לקוח יכול להשוות את מחיר המוצר הזמין במקומות שונים בזמן אמת.
לכן, תמחור תחרותי הוא דבר שהפך לחלק המכריע ביותר באסטרטגיה עסקית.
על מנת לשמור על מחירי המוצרים שלך תחרותיים ואטרקטיביים, עליך לעקוב אחר ולעקוב אחר המחירים שקבעו המתחרים שלך. אם אתה יודע מהי אסטרטגיית התמחור של המתחרים שלך, תוכל להתאים בהתאם את אסטרטגיית התמחור שלך כדי להשיג יתרון עליהם.
מכאן שמעקב אחר מחירים הפך לחלק חיוני בתהליך ניהול עסק מסחר אלקטרוני.
אתה עשוי לתהות כיצד להחזיק את הנתונים להשוואת מחירים.
שלוש הדרכים המובילות להשגת הנתונים הדרושים לצורך השוואת מחירים
1. הזנות מסוחרים
כפי שאתה אולי יודע, ישנם מספר אתרי השוואת מחירים הזמינים באינטרנט. אתרים אלו נכנסים למעין הבנות עם העסקים שבהם הם מקבלים את הנתונים ישירות מהם ואשר הם משתמשים לשם השוואת מחירים.
עסקים אלה מקימים API, או משתמשים ב- FTP כדי לספק את הנתונים. ככלל, ועדת הפניות היא שהופכת את אתר השוואת מחירים למשתלם כלכלית.
2. הזנות מוצרים מממשקי API של צד שלישי
מצד שני, ישנם שירותים המציעים נתוני מסחר אלקטרוני באמצעות API. כאשר משתמשים בשירות כזה, הצד השלישי משלם עבור נפח הנתונים.
3. גירוד באינטרנט
גירוד באינטרנט הוא אחת הדרכים החזקות והאמינות ביותר להשיג נתוני אינטרנט מהאינטרנט. משתמשים בה יותר ויותר במודיעין מחירים מכיוון שזו דרך יעילה להשיג את נתוני המוצרים מאתרי מסחר אלקטרוני.
יתכן שלא תהיה לך גישה לאפשרות הראשונה והשנייה. לפיכך, גירוד באינטרנט יכול לבוא לעזרתך. אתה יכול להשתמש בגרידה באינטרנט כדי למנף את כוח הנתונים כדי להגיע לתמחור תחרותי עבור העסק שלך.
באמצעות גרידה באינטרנט ניתן להשיג מחירים שוטפים לתרחיש השוק הנוכחי, ולסחר אלקטרוני באופן כללי יותר. נשתמש בגרידה באינטרנט כדי לקבל את הנתונים מאתר מסחר אלקטרוני. בבלוג זה תלמד כיצד לגרד שמות ומחירים של מוצרים מאמזון בכל הקטגוריות, תחת מותג מסוים.
חילוץ נתונים מאמזון מעת לעת יכול לעזור לך לעקוב אחר מגמות התמחור בשוק ולאפשר לך לקבוע את המחירים בהתאם.
תוכן עניינים
- גרידת רשת להשוואת מחירים
- גרידה באינטרנט ב- R
- יישום
- תו סיום
1. גרידת רשת להשוואת מחירים
כמו שאומרת חוכמת השוק, המחיר הוא הכל. הלקוחות מקבלים את החלטות הרכישה שלהם על סמך מחיר. הם מבססים את הבנתם את איכות המוצר על מחיר. בקיצור, המחיר הוא שמניע את הלקוחות ומכאן גם את השוק.
לכן, אתרי השוואת המחירים מבוקשים מאוד. לקוחות יכולים לנווט בקלות בכל השוק על ידי התבוננות במחירים של אותו מוצר בכל המותגים. אתרי השוואת מחירים אלו מפיקים את מחירו של אותו מוצר מאתרים שונים.
לצד המחירים, אתרי השוואת מחירים מגרדים גם נתונים כמו תיאור המוצר, המפרט הטכני והתכונות. הם מקרינים את כל טווח המידע על דף אחד באופן השוואתי.
זה עונה על השאלה שהקונה הפוטנציאלי שאל בחיפושיו. כעת הקונה הפוטנציאלי יכול להשוות את המוצרים ומחיריהם, יחד עם מידע כגון תכונות, תשלום ואפשרויות משלוח, כדי שיוכלו לזהות את העסקה הטובה ביותר האפשרית.
אופטימיזציה לתמחור משפיעה על העסק במובן שטכניקות כאלה יכולות לשפר את שולי הרווח ב -10%.
מסחר אלקטרוני מתייחס לתמחור תחרותי, והוא התפשט גם לתחומים עסקיים אחרים. קח את מקרה הנסיעות. כעת גם אתרים הקשורים לנסיעות מגרדים את המחיר מאתרי חברות התעופה בזמן אמת כדי לספק השוואת מחירים של חברות תעופה שונות.
האתגר היחיד בכך הוא לעדכן את הנתונים בזמן אמת ולהתעדכן בכל שנייה כאשר המחירים ממשיכים להשתנות באתרי המקור. אתרי השוואת מחירים משתמשים במשרות Cron או בזמן הצפייה כדי לעדכן את המחיר. עם זאת, הוא יונח על התצורה של בעל האתר.
זה המקום בו הבלוג הזה יכול לעזור לך - תוכל לעבוד על סקריפט גירוד שתוכל להתאים אישית לצרכים שלך. תוכל לחלץ עדכוני מוצרים, תמונות, מחיר וכל שאר הפרטים הרלוונטיים הנוגעים למוצר ממספר אתרים שונים. בעזרת זה תוכל ליצור את מסד הנתונים החזק שלך לאתר השוואת מחירים.
2. גרידת רשת ב- R
השוואת מחירים הופכת להיות מסורבלת מכיוון שקבלת נתוני רשת אינה כל כך קלה - ישנן טכנולוגיות כמו HTML, XML ו- JSON להפצת התוכן.
לכן, על מנת לקבל את הנתונים שאתה צריך, עליך לנווט ביעילות בטכנולוגיות שונות אלה. R יכול לעזור לך לגשת לנתונים המאוחסנים בטכנולוגיות אלה. עם זאת, זה דורש הבנה מעמיקה של R לפני שתתחיל.
מה זה R?
גירוד באינטרנט הוא משימה מתקדמת שלא הרבה אנשים מבצעים. גרידה באינטרנט עם R היא, בוודאי, תכנות טכני ומתקדם. הבנה מספקת של R חיונית לגרידה באינטרנט בצורה זו.
ראשית, R היא שפה למחשוב וגרפיקה סטטיסטית. סטטיסטיקאים וכורי נתונים משתמשים ב- R הרבה בשל התוכנה הסטטיסטית המתפתחת שלה, והתמקדותה בניתוח נתונים.
אחת הסיבות ש- R הוא כל כך מועדף בקרב קבוצה זו של אנשים היא איכות העלילות שניתן לעבד, כולל סמלים ומתמונות מתמטית בכל מקום שנדרש.
R הוא נפלא מכיוון שהוא מציע מגוון עצום של פונקציות וחבילות שיכולות להתמודד עם משימות כריית נתונים.
rvest, RCrawler וכו 'הם חבילות R המשמשות לתהליכי איסוף נתונים.
בקטע זה נראה אילו כלים נדרשים לעבודה עם R לצורך גרידת רשת. נראה את זה דרך מקרה השימוש באתר אמזון ממנו ננסה להשיג את נתוני המוצר ולאחסן אותם בצורה JSON.
דרישות
במקרה שימוש זה, ידע של R הוא חיוני ואני מניח שיש לך הבנה בסיסית של R . אתה צריך להיות מודע לפחות לכל ממשק R אחד, כגון RStudio. ממשק ההתקנה R הבסיסי בסדר.
אם אינך מודע ל- R ולממשקים המשויכים האחרים, עליך לעבור על מדריך זה.
עכשיו בואו נבין כיצד יותקנו החבילות בהן אנו משתמשים.
חבילות:
1. rvest
הדלי וויקהאם חיברה את חבילת rvest לגרידה ברשת ב- R. rvest שימושי בהפקת המידע הדרוש לך מדפי האינטרנט.
Along with this, you also need to install the selectr and ‘xml2’ packages.
Installation steps:
install.packages(‘selectr’)
install.packages(‘xml2’)
install.packages(‘rvest’)
rvest contains the basic web scraping functions, which are quite effective. Using the following functions, we will try to extract the data from web sites.
read_html(url)
: scrape HTML content from a given URLhtml_nodes()
: identifies HTML wrappers.html_nodes(“.class”)
: calls node based on CSS classhtml_nodes(“#id”)
: calls node based on idhtml_nodes(xpath=”xpath”)
: calls node based on xpath (we’ll cover this later)html_attrs()
: identifies attributes (useful for debugging)html_table()
: turns HTML tables into data frameshtml_text()
: strips the HTML tags and extracts only the text
2. stringr
stringr comes into play when you think of tasks related to data cleaning and preparation.
There are four essential sets of functions in stringr:
- stringr functions are useful because they enable you to work around the individual characters within the strings in character vectors
- there are whitespace tools which can be used to add, remove, and manipulate whitespace
- there are locale sensitive operations whose operations will differ from locale to locale
- there are pattern matching functions. These functions recognize four parts of pattern description. Regular expressions are the standard one but there are other tools as well
Installation
install.packages(‘stringr’)
3. jsonlite
What makes the jsonline package useful is that it is a JSON parser/generator which is optimized for the web.
It is vital because it enables an effective mapping between JSON data and the crucial R data types. Using this, we are able to convert between R objects and JSON without loss of type or information, and without the need for any manual data wrangling.
This works really well for interacting with web APIs, or if you want to create ways through which data can travel in and out of R using JSON.
Installation
install.packages(‘jsonlite’)
Before we jump-start into it, let’s see how it works:
It should be clear at the outset that each website is different, because the coding that goes into a website is different.
Web scraping is the technique of identifying and using these patterns of coding to extract the data you need. Your browser makes the website available to you from HTML. Web scraping is simply about parsing the HTML made available to you from your browser.
Web scraping has a set process that works like this, generally:
- Access a page from R
- Instruct R where to “look” on the page
- Convert data in a usable format within R using the rvest package
Now let’s go to implementation to understand it better.
3. Implementation
Let’s implement it and see how it works. We will scrape the Amazon website for the price comparison of a product called “One Plus 6”, a mobile phone.
You can see it here.
Step 1: Loading the packages we need
We need to be in the console, at R command prompt to start the process. Once we are there, we need to load the packages required as shown below:
#loading the package:> library(xml2)> library(rvest)> library(stringr)
Step 2: Reading the HTML content from Amazon
#Specifying the url for desired website to be scrappedurl <- ‘//www.amazon.in/OnePlus-Mirror-Black-64GB-Memory/dp/B0756Z43QS?tag=googinhydr18418-21&tag=googinkenshoo-21&ascsubtag=aee9a916-6acd-4409-92ca-3bdbeb549f80’
#Reading the html content from Amazonwebpage <- read_html(url)
In this code, we read the HTML content from the given URL, and assign that HTML into the webpage
variable.
Step 3: Scrape product details from Amazon
Now, as the next step, we will extract the following information from the website:
Title: The title of the product.
Price: The price of the product.
Description: The description of the product.
Rating: The user rating of the product.
Size: The size of the product.
Color: The color of the product.
This screenshot shows how these fields are arranged.

Next, we will make use of HTML tags, like the title of the product and price, for extracting data using Inspect Element.
In order to find out the class of the HTML tag, use the following steps:
=> go to chrome browser => go to this URL => right click => inspect element
NOTE: If you are not using the Chrome browser, check out this article.
Based on CSS selectors such as class and id, we will scrape the data from the HTML. To find the CSS class for the product title, we need to right-click on title and select “Inspect” or “Inspect Element”.

As you can see below, I extracted the title of the product with the help of html_nodes
in which I passed the id of the title — h1#title
— and webpage
which had stored HTML content.
I could also get the title text using html_text
and print the text of the title with the help of the head ()
function.
#scrape title of the product> title_html title head(title)
The output is shown below:

We could get the title of the product using spaces and \n.
The next step would be to remove spaces and new line with the help of the str_replace_all()
function in the stringr library.
# remove all space and new linesstr_replace_all(title, “[\r\n]” , “”)
Output:

Now we will need to extract the other related information of the product following the same process.
Price of the product:
# scrape the price of the product> price_html price <- html_text(price_html)
# remove spaces and new line> str_replace_all(title, “[\r\n]” , “”)
# print price value> head(price)
Output:

Product description:
# scrape product description> desc_html desc <- html_text(desc_html)
# replace new lines and spaces> desc desc head(desc)
Output:

Rating of the product:
# scrape product rating > rate_html rate <- html_text(rate_html)
# remove spaces and newlines and tabs > rate rate <- str_trim(rate)
# print rating of the product> head(rate)
Output:

Size of the product:
# Scrape size of the product> size_html size_html size <- html_text(size_html)
# remove tab from text> size <- str_trim(size)
# Print product size> head(size)
Output:

Color of the product:
# Scrape product color> color_html color_html color <- html_text(color_html)
# remove tabs from text> color <- str_trim(color)
# print product color> head(color)
Output:

Step 4: We have successfully extracted data from all the fields which can be used to compare the product information from another site.
Let’s compile and combine them to work out a dataframe and inspect its structure.
#Combining all the lists to form a data frameproduct_data <- data.frame(Title = title, Price = price,Description = desc, Rating = rate, Size = size, Color = color)
#Structure of the data framestr(product_data)
Output:

In this output we can see all the scraped data in the data frames.
Step 5: Store data in JSON format:
As the data is collected, we can carry out different tasks on it such as compare, analyze, and arrive at business insights about it. Based on this data, we can think of training machine learning models over this.
Data would be stored in JSON format for further process.
Follow the given code and get the JSON result.
# Include ‘jsonlite’ library to convert in JSON form.> library(jsonlite)
# convert dataframe into JSON format> json_data <- toJSON(product_data)
# print output> cat(json_data)
In the code above, I have included jsonlite
library for using the toJSON()
function to convert the dataframe object into JSON form.
At the end of the process, we have stored data in JSON format and printed it.
It is possible to store data in a csv file also or in the database for further processing, if we wish.
Output:

Following this practical example, you can also extract the relevant data for the same from product from //www.oneplus.in/6 and compare with Amazon to work out the fair value of the product. In the same way, you can use the data to compare it with other websites.
4. End note
As you can see, R can give you great leverage in scraping data from different websites. With this practical illustration of how R can be used, you can now explore it on your own and extract product data from Amazon or any other e-commerce website.
A word of caution for you: certain websites have anti-scraping policies. If you overdo it, you will be blocked and you will begin to see captchas instead of product details. Of course, you can also learn to work your way around the captchas using different services available. However, you do need to understand the legality of scraping data and whatever you are doing with the scraped data.
Feel free to send to me your feedback and suggestions regarding this post!