어두운 proxyscrape 로고

Web Scraping for Price Comparison in 2024– Easy Steps

Python, 스크래핑, 1월-03-20235분 읽기

웹 스크래핑은 인터넷에서 데이터를 추출하는 기술입니다. 웹 스크래핑의 응용 분야는 방대합니다. 그 중 하나는 여러 웹사이트의 가격 비교입니다. 온라인 쇼핑은 현재 업계에서 붐을 일으키고 있으며, 특정 제품의 가격을 비교하는 것은 필수가 되었습니다. 우리는 모두 특정 제품을 구매해야 할 때 여러 웹사이트를 방문하지만, 동일한 작업을 수행하고 최상의 거래를 제시하는 가격 비교 도구를 만드는 것에 대해 생각해 본 적이 있나요?  

이 글에서는 다양한 소스에서 제품의 가격을 추적하고 시장의 다양한 경쟁업체의 성능을 알려주는 놀라운 웹 스크래핑 가격 비교 도구를 파이썬으로 만들어 보겠습니다. 또한 특정 제품의 가격이 예상 가격보다 오르거나 내려가는지 여부도 알려줍니다.

이 글에서 사용할 데이터 소스는 JSON 파일이며, 아마존, eBay, 월마트에서 가져온 제품 가격을 비교하겠습니다. 샘플 데이터는 아래와 같습니다,

파이썬에서 가격 비교를 위한 웹 스크래핑에 대해 자세히 알아보려면 원하는 섹션으로 자유롭게 이동하세요!

목차

가격 비교를 위한 웹 스크래핑에 관련된 단계:

[
  {
    "last_visited": "2018-01-30T13:38:01",
    "name": "PUMA Men's Evospeed 17.4 TT Soccer Shoe",
    "amazon_price": 36.94,
    "ebay_price": 37,
    "walmart_price": 37,
    "amazon_url": "https://www.amazon.com/PUMA-Evospeed-Soccer-Ultra-Yellow-Peacoat-Orange/dp/B01J5LEMZI/",
    "ebay_url": "https://www.ebay.com/itm/PUMA-Mens-Evospeed-17-4-Tt-Soccer-Shoe/302471489090",
    "walmart_url": "https://www.walmart.com/ip/PUMA-Men-s-Evospeed-17-4-Tt-Soccer-Shoe/587074448",
    "description": "The new evospeed 17.4 is a performance football boot for players of all levels. The soft and lightweight synthetic leather on the upper keeps the boot lightweight, comfortable and ensures durability. The lightweight outsole offers the perfect balance between traction, stability and acceleration PUMA is the global athletic brand that successfully fuses influences from sport, lifestyle and fashion. PUMA's unique industry perspective delivers the unexpected in sport-lifestyle footwear, apparel and accessories, through technical innovation and revolutionary design.",
    "brand": "PUMA",
    "image": "https://images-na.ssl-images-amazon.com/images/I/61v1mylcAqL._UL1500_.jpg"
  },
  {
    "last_visited": "2018-01-30T13:38:07",
    "name": "L'Oreal Paris Skin Care Revitalift Cicacream Face Moisturizer",
    "amazon_price": 13.97,
    "ebay_price": 13.99,
    "walmart_price": 13.97,
    "amazon_url": "https://www.amazon.com/LOreal-Paris-Revitalift-Cicacream-Moisturizer/dp/B074MBDRHW",
    "ebay_url": "https://www.ebay.com/itm/LOREAL-Paris-NEW-Revitalift-Cicacream-Anti-Wrinkle-Skin-Barrier-Repair-ORIGINAL/112715734801",
    "walmart_url": "https://www.walmart.com/ip/L-Or-al-Paris-Revitalift-Cicacream-Anti-Wrinkle-Skin-Barrier-Repair/519350834",
    "description": "Skin's moisture barrier weakens with age, resulting in greater moisture loss, more prominent wrinkles and loss of firmness. Lightweight, protective cream is formulated with Pro-Retinol, a powerful wrinkle-fighting ingredient and Centella Asiatica, an herb used in traditional Chinese medicine. Strengthens and repairs skin barrier to help resist visible lines, loss of firmness and other signs of aging that a weakened skin barrier can accentuate. See visible results immediately: skin feels healthier, softer, smoother and more supple. Skin feels noticeably more hydrated. Skin barrier is stronger, helping to resist signs of aging. In two weeks: fine lines appear visibly reduced. Firmness and elasticity look noticeably improved. In four weeks: wrinkles appear less visible. Clarity and tone improves, skin exudes luminosity. Skin continues to look and feel soft, smooth, healthy.",
    "brand": "L'Oreal Paris",
    "image": "https://images-na.ssl-images-amazon.com/images/I/71Ff2vn4vjL._SL1500_.jpg"
  },
  {
    "last_visited": "2018-01-30T13:38:12",
    "name": "Adidas Dynamic Pulse By Adidas For Men",
    "amazon_price": 6.96,
    "ebay_price": 18.99,
    "walmart_price": 7,
    "amazon_url": "https://www.amazon.com/Adidas-Dynamic-Toilette-3-4-Ounce-Bottle/dp/B000VON5F2/",
    "ebay_url": "https://www.ebay.com/itm/Adidas-DYNAMIC-PULSE-Cologne-for-Men-3-4-oz-edt-3-3-Spray-New-in-BOX/252837623533",
    "walmart_url": "https://www.walmart.com/ip/Adidas-Dynamic-Pulse-for-Men-3-4-oz-EDT/28664356",
    "description": "Launched by the design house of Adidas in 1997, ADIDAS DYNAMIC PULSE is a men's fragrance that possesses a blend of A fresh scent of citrus, cedar and mint with low tones of sweet fruits, fragrant woods and tonka bean. It is recommended for daytime wear.When applying any fragrance please consider that there are several factors which can affect the natural smell of your skin and, in turn, the way a scent smells on you. For instance, your mood, stress level, age, body chemistry, diet, and current medications may all alter the scents you wear. Similarly, factor such as dry or oily skin can even affect the amount of time a fragrance will last after being applied",
    "brand": "adidas",
    "image": "https://images-na.ssl-images-amazon.com/images/I/41%2BAnOP5nbL.jpg"
  },
  {
    "last_visited": "2018-01-30T13:38:19",
    "name": "Canon EOS Rebel T6 Digital SLR Camera",
    "amazon_price": 449,
    "ebay_price": 449,
    "walmart_price": 449,
    "amazon_url": "https://www.amazon.com/Canon-Digital-Camera-18-55mm-3-5-5-6/dp/B01CO2JPYS",
    "ebay_url": "https://www.ebay.com/itm/Canon-EOS-Rebel-T6-DSLR-Camera-with-18-55mm-Lens/232596041502",
    "walmart_url": "https://www.walmart.com/ip/Canon-EOS-Rebel-T6-DSLR-Camera-with-18-55mm-Lens-Black/50820749",
    "description": "",
    "brand": "Canon",
    "image": "https://images-na.ssl-images-amazon.com/images/I/81YszfZS8%2BL._SL1500_.jpg"
  },
  {
    "last_visited": "2018-01-30T13:38:25",
    "name": "Woodland Fox Critter 36' Mylar Balloon",
    "amazon_price": 5.49,
    "ebay_price": 6.49,
    "walmart_price": 7.6,
    "amazon_url": "https://www.amazon.com/Woodland-Fox-Critter-Mylar-Balloon/dp/B00S9TKVYO",
    "ebay_url": "https://www.ebay.com/itm/Woodland-Critters-Fox-36-inch-Foil-Balloon/132058119680",
    "walmart_url": "https://www.walmart.com/ip/Woodland-Fox-Foil-Balloon/43350002",
    "description": "Celebrate any occasion with an adorable woodland fox critter balloon! 36\" Woodland Critters fox shape foil balloon.",
    "brand": "Betallic",
    "image": "https://images-na.ssl-images-amazon.com/images/I/71Z9bG-BzuL._SL1500_.jpg"
  }
]

우리가 작성 중인 스크립트와 관련된 중요한 필드 중 일부는 amazon_price, ebay_pricewalmart_price입니다.

이제 데이터를 확인했습니다. 이제 개발 단계로 들어가 보겠습니다.

이 도구는 Python 3.x로 만들 예정이며, 우선 JSON 구문 분석 및 추가 처리를 위해 JSON 라이브러리를 사용할 것입니다. 이 도구는 사이트의 제품 이름과 가격을 인쇄하여 놀라운 기능을 제공합니다. JSON을 파싱하기 위해 JSON 라이브러리를 가져오고 있습니다.

json 가져오기

이제 코드 스니펫에서 open() 함수를 호출하여 JSON 파일에서 콘텐츠를 읽겠습니다,

json 가져오기 
 
if __name__ == '__main__':
    price_data = None
    price = []
   열다('data.json', encoding='utf8')  f로 사용합니다:
        price_data = f.read()
 
    price_data가 None이 아닌 경우 
       json_price_data = json.loads(price_data)

이제 JSON 데이터를 읽었으니, 이 데이터를 파이썬의 내장 데이터 구조로 변환하여 항목에 따라 json.loads() 메서드를 호출하여 JSON 문자열을 사전 또는 사전 목록으로 변환할 것입니다.

주요 목표는 제품을 가장 낮은 가격에 판매하는 스토어를 찾는 것이므로, 최저 가격과 제품 및 스토어 이름과 같은 기타 관련 세부 정보를 찾는 것이 목표입니다. 관련 상점의 가격 정보는 amazon_price, ebay_price Walmart_price 키에 저장됩니다. 각 제품의 최저가를 찾으려면 가격표 항목을 반복해야 합니다.

for d in json_price_data:
            price.append({'name': d['name'], 'price': float(d['amazon_price']), 'url': d['amazon_url']})
            price.append({'name': d['name'], 'price': float(d['walmart_price']), 'url': d['walmart_url']})
            price.append({'name': d['name'], 'price': float(d['ebay_price']), 'url': d['ebay_url']})
            minPricedItem = min(price, key=lambda x: x['price'])
            print(minPricedItem)
            print('=================')
            price = []

람다를 사용하고 min() 키를 설정하여 가격 필드가 비교되고 있는지 확인합니다. 다음과 같은 출력을 생성합니다:

형식을 약간 재구성해 보겠습니다.

for d in json_price_data:
            price.append({'name': d['name'], 'price': d['amazon_price'], 'url': d['amazon_url']})
            price.append({'name': d['name'], 'price': d['walmart_price'], 'url': d['walmart_url']})
            price.append({'name': d['name'], 'price': d['ebay_price'], 'url': d['ebay_url']})
            minPricedItem = min(price, key=lambda x: float(x['price']))
            store_name = ''
            # Pick the store name based on url
            if 'amazon' in minPricedItem['url'].lower():
                store_name = 'Amazon'
            elif 'walmart' in minPricedItem['url'].lower():
                store_name = 'Amazon'
            elif 'ebay' in minPricedItem['url'].lower():
                store_name = 'eBay'
            print('{} is available in cheap price at {}. The price is ${}'.format(minPricedItem['name'], store_name,
                                                                                 minPricedItem['price']))
            price = []

다음과 같은 출력이 표시됩니다:

축하합니다! 주기적으로 실행하여 제품의 업데이트된 가격을 확인할 수 있는 스크립트를 성공적으로 만들었습니다.

파이썬을 사용하여 가격 비교를 위한 웹 스크래핑에 가장 적합한 프록시는 무엇인가요?

ProxyScrape 는 온라인에서 가장 인기 있고 신뢰할 수 있는 프록시 제공업체 중 하나입니다. 세 가지 프록시 서비스에는 전용 데이터센터 프록시 서버, 주거용 프록시 서버, 프리미엄 프록시 서버가 있습니다. 그렇다면 파이썬을 사용하여 가격 비교를 위한 웹 스크래핑에 가장 적합한 HTTP 프록시 솔루션은 무엇일까요? 이 질문에 답하기 전에 각 프록시 서버의 기능을 살펴보는 것이 가장 좋습니다.

전용 데이터센터 프록시 는 분석 목적으로 다양한 서버에서 대량의 데이터(크기 기준)를 스트리밍하는 등 고속 온라인 작업에 가장 적합합니다. 이는 조직이 단시간에 대량의 데이터를 전송하기 위해 전용 프록시를 선택하는 주된 이유 중 하나입니다.

전용 데이터센터 프록시는 무제한 대역폭 및 동시 연결, 간편한 통신을 위한 전용 HTTP 프록시, 보안 강화를 위한 IP 인증 등 다양한 기능을 제공합니다. 99.9%의 가동 시간으로 어떤 세션 중에도 전용 데이터센터가 항상 작동하므로 안심할 수 있습니다. 마지막으로 ProxyScrape 은 우수한 고객 서비스를 제공하며 영업일 기준 24~48시간 이내에 문제를 해결할 수 있도록 도와드립니다. 

다음은 주거용 프록시입니다. 주거용 프록시는 모든 일반 소비자가 사용하는 프록시입니다. 주된 이유는 주거용 프록시의 IP 주소가 ISP에서 제공하는 IP 주소와 유사하기 때문입니다. 즉, 대상 서버의 데이터에 액세스할 수 있는 권한을 평소보다 쉽게 얻을 수 있습니다. 

ProxyScrape의 또 다른 기능은 로테이팅 기능입니다. 로테이팅 프록시를 사용하면 주거용 프록시가 IP 주소를 동적으로 변경하여 대상 서버가 프록시 사용 여부를 확인하기 어렵기 때문에 계정이 영구적으로 차단되는 것을 방지할 수 있습니다. 

그 외에도 무제한 대역폭과 동시 연결, 전용 HTTP/s 프록시, 프록시 풀에 있는 700만 개 이상의 프록시를 통해 언제든지 세션에서 프록시, 보안 강화를 위한 사용자 이름 및 비밀번호 인증, 마지막으로 국가 서버 변경 기능 등 다양한 기능이 있습니다. 사용자 아이디 인증에 국가 코드를 추가하여 원하는 서버를 선택할 수 있습니다. 

마지막은 프리미엄 프록시입니다. 프리미엄 프록시는 전용 데이터센터 프록시와 동일합니다. 기능은 동일하게 유지됩니다. 가장 큰 차이점은 접근성입니다. 프리미엄 프록시에서는 프록시 목록(프록시가 포함된 목록)을 ProxyScrape네트워크의 모든 사용자가 사용할 수 있습니다. 그렇기 때문에 프리미엄 프록시는 전용 데이터센터 프록시보다 비용이 저렴합니다.

그렇다면 파이썬을 사용하여 가격 비교를 위한 웹 스크래핑에 가장 적합한 HTTP 프록시 솔루션은 무엇일까요? 정답은 "주거용 프록시." 이유는 간단합니다. 위에서 말했듯이 주거용 프록시는 순환 프록시로, 일정 기간 동안 IP 주소가 동적으로 변경되므로 짧은 시간 내에 많은 요청을 전송하여 IP 차단을 받지 않고 서버를 속이는 데 유용할 수 있습니다. 

다음으로 가장 좋은 방법은 국가를 기준으로 프록시 서버를 변경하는 것입니다. IP 인증 또는 사용자 이름 및 비밀번호 인증 끝에 국가 ISO_CODE를 추가하기만 하면 됩니다. 

추천 읽기:

  1. YouTube 댓글 스크랩 - 간단한 5단계
  2. 2023년 최고의 파이썬 웹 스크래핑 도구 상위 8가지
  3. 파이썬을 사용한 뉴스 기사 웹 스크래핑 - 2023년 가장 좋은 방법

자주 묻는 질문:

1. 가격 스크래핑이란 무엇인가요?
가격 스크래핑은 이름에서 알 수 있듯이 마케팅 전략을 개선하기 위해 온라인에서 제품이나 서비스의 가격을 추출하여 경쟁사 분석과 같은 분석을 수행하는 프로세스입니다. 스크래핑 프로세스를 자동화하면 시간과 리소스를 줄이는 데 도움이 될 수 있으며, 파이썬의 도움으로 이를 수행할 수 있습니다.
2. 가격 비교를 위한 웹 스크래핑에 가장 적합한 프록시는 무엇인가요?
The best proxy to perform web scraping for price comparison is a “residential proxy.” The reason is that the residential proxy is a rotating proxy, meaning that your IP address would be dynamically changed over a period of time which can be helpful to trick the server by sending a lot of requests within a small time frame without getting an IP block.
3. 가격 비교를 위한 웹 스크래핑은 합법인가요?
대답은 '예'입니다. 모든 정보가 공개되어 있으므로 전자상거래 웹사이트에서 가격을 스크랩할 수 있으며, 이는 모든 공개 데이터를 스크랩할 수 있음을 의미합니다.

결론

이번 글에서는 웹 스크래핑의 또 하나의 경이로움, 즉 '가격 비교'에 대해 살펴보았습니다. 이뿐만 아니라, 가격 비교 작업을 대신 해주고 시장 동향을 계속 업데이트할 수 있는 도구를 만들었습니다. 이 글은 가격 비교를 위한 웹 스크래핑에 대한 충분한 정보를 쉬운 방법으로 제공하고자 합니다. 프록시 서버는 웹 스크래핑을 위한 최고의 동반자입니다. ProxyScrape 는 가격 비교 프로젝트를 위한 웹 스크래핑을 위한 동급 최고의 주거용 프록시를 제공합니다. 여기에서 최고의 주거용 프록시를 확인할 수 있습니다.