Skip to content

Instantly share code, notes, and snippets.

@innfinite4evr
Last active August 12, 2019 18:19
Show Gist options
  • Save innfinite4evr/d7bdf973905546af51ac9d415148daf2 to your computer and use it in GitHub Desktop.
Save innfinite4evr/d7bdf973905546af51ac9d415148daf2 to your computer and use it in GitHub Desktop.
2gud scraper
####################################
# BY @ INNFINITE4EVR
####################################
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import time
#headers rip user agent
# 2gud search url
surl='https://www.2gud.com/search'
def get(url):
oparams = (
('sid', '2gd,kns,fht'),
('otracker', 'CLP_Filters'),
('p[]', ['facets.processor_brand[]=Snapdragon', 'facets.price_range.from=Min', 'facets.price_range.to=7000', 'facets.operating_system[]=Android', 'facets.type[]=Smartphones', 'facets.ram[]=2 GB', 'facets.ram[]=3 GB', 'facets.ram[]=4 GB', offer]),
('sort', 'price_asc'),
)
src = requests.get(url, params=oparams)
soup = BeautifulSoup(src.text, 'lxml')
#print(soup.prettify())
soup.find(True, {'class':['_1YuAuf', '_3ywJNQ', '_1joEet']}).decompose()
for div in soup.findAll("div", {"class": "_1HmYoV _35HD7C"}):
#print(div)
for title in div.findAll('a',target='_blank'):
str=title.text
title=str.replace("₹"," ₹").replace(" ₹","Offer Price:₹", 1).replace(" ₹"," Regular Price:₹", 1).replace(str[-7:]," "+str[-7:])
print(title)
ans=True
while ans:
print ("""
1.Get Special Prices
2.Get all products
3.Exit/Quit
""")
ans=input("What would you like to do? ")
if ans=="1":
print("\n Special Prices")
offer='facets.offer_type[]=Special Price'
get(surl)
elif ans=="2":
print("\n All products")
offer='facets.offer_type[]=null'
get(surl)
elif ans=="3":
print("\n Goodbye,,,")
time.sleep(2)
exit()
elif ans !="":
print("\n Not Valid Choice Try again")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment