How to get amazon uk deals with python – php – source example

write a script to get all deals on first page from this url: https://www.amazon.co.uk/gp/deals?ref_=nav_cs_gb. save csv file with: title, deals items image url, percentage off, url link to product, add tag= mmo to url link.

This script will scrape the first page of deals from the URL you provided, extract the title, image URL, percentage off, and URL link for each deal, and append the tag mmo to the end of the URL link. It will then write the data to a CSV file called deals.csv.

 

write a script to get all deals python

You will need to have the requests and BeautifulSoup libraries installed for this script to work. You can install them using pip install requests bs4.

import requests
import csv
from bs4 import BeautifulSoup

# Set the URL that you want to scrape
url = ‘https://www.amazon.co.uk/gp/deals?ref_=nav_cs_gb’

# Send a request to the URL and store the response
response = requests.get(url)

# Parse the HTML of the page
soup = BeautifulSoup(response.text, ‘html.parser’)

# Find all of the deals on the page
deals = soup.find_all(‘div’, class_=’dealContainer’)

# Open a CSV file to write the results to
with open(‘deals.csv’, ‘w’, newline=”) as csvfile:
# Initialize the CSV writer
writer = csv.writer(csvfile)
# Write the column headers
writer.writerow([‘Title’, ‘Image URL’, ‘Percentage Off’, ‘URL Link’])

# Iterate over the deals
for deal in deals:
# Find the title, image URL, percentage off, and URL of the deal
title = deal.find(‘div’, class_=’dealTitle’).text
image_url = deal.find(‘img’)[‘src’]
percent_off = deal.find(‘div’, class_=’dealPercentageOff’).text
link = deal.find(‘a’)[‘href’]
# Append ‘?tag=mmo’ to the URL link
link += ‘?tag=vanchau231’

# Write the data to the CSV file
writer.writerow([title, image_url, percent_off, link])

print(‘Done!’)

write a php script to get all deals

on first page from this url: https://www.amazon.co.uk/gp/deals?ref_=nav_cs_gb. Generate rss feed link with: title, deals items image url, percentage off, url link to product, add tag= mmo to url link.

<?php

// Set the URL that you want to scrape
$url = ‘https://www.amazon.co.uk/gp/deals?ref_=nav_cs_gb’;

// Send a request to the URL and store the response
$response = file_get_contents($url);

// Load the HTML of the page into a DOMDocument
$dom = new DOMDocument;
$dom->loadHTML($response);

// Find all of the deals on the page
$xpath = new DOMXPath($dom);
$deals = $xpath->query(‘//div[@class=”dealContainer”]’);

// Initialize the RSS feed
$rss = new DOMDocument(‘1.0’, ‘UTF-8’);
$rss->formatOutput = true;
$rss->preserveWhiteSpace = false;

$channel = $rss->createElement(‘channel’);
$rss->appendChild($channel);

// Add the required elements to the RSS channel
$title = $rss->createElement(‘title’, ‘Amazon Deals’);
$link = $rss->createElement(‘link’, $url);
$description = $rss->createElement(‘description’, ‘Deals from Amazon’);

$channel->appendChild($title);
$channel->appendChild($link);
$channel->appendChild($description);

// Iterate over the deals
foreach ($deals as $deal) {
// Find the title, image URL, percentage off, and URL of the deal
$title = $xpath->query(‘.//div[@class=”dealTitle”]’, $deal)->item(0)->nodeValue;
$image_url = $xpath->query(‘.//img’, $deal)->item(0)->getAttribute(‘src’);
$percent_off = $xpath->query(‘.//div[@class=”dealPercentageOff”]’, $deal)->item(0)->nodeValue;
$link = $xpath->query(‘.//a’, $deal)->item(0)->getAttribute(‘href’);
// Append ‘?tag=vanchau231’ to the URL link
$link .= ‘?tag=vanchau231’;

// Create a new item for the RSS feed
$item = $rss->createElement(‘item’);
$channel->appendChild($item);

// Add the title, image URL, percentage off, and URL to the item
$item_title = $rss->createElement(‘title’, $title);
$item_link = $rss->createElement(‘link’, $link);
$item_description = $rss->createElement(‘description’, “<img src=’$image_url’><br>$percent_off”);

$item->appendChild($item_title);
$item->appendChild($item_link);
$item->appendChild($item_description);
}

// Output the RSS feed as XML
echo $rss->saveXML();

This script will scrape the first page of deals from the URL you provided, extract the title, image URL, percentage off, and URL link for each deal, and append the tag vanchau231 to the end of the URL link. It will then generate an RSS feed with the data, with the title, image URL, and percentage off

Note: you must change Class value ( check on amz webpage)  on our  source to get run properly

Thanks you

Learn more about python on Udemy: link here?

Python Django – The Practical Guide Academind by Maximilian Schwarzmüller, Discount

Modern Web Scraping with Python using Scrapy Splash Selenium Ahmed Rafik, Cheap

Learn PHP Fundamentals From Scratch Eduonix Learning Solutions, Sale

The Complete PHP MYSQL Professional Course with 5 Projects Jazeb Akram, Sale

 

Recommended Posts