-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfone_scraper.py
28 lines (25 loc) · 964 Bytes
/
justfone_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
from bs4 import BeautifulSoup
def justfone_scraper(x):
result = []
url="https://justfones.ng/catalogsearch/result/?cat=&q={}".format(x)
http=requests.get(url)
if http.status_code!=200:
raise "ErrorGettingPage"
try:
soup=BeautifulSoup(http.text,"lxml")
item_list = soup.find_all(class_="item last")
if (item_list!=None):
all_items = item_list
except AttributeError:
raise AttributeError
def get_details():
lst = all_items
for i in range(len(all_items)):
name = lst[i].find(class_="product-name").find(text=True)
price = lst[i].find(class_="price").getText()
link = lst[i].find(attrs={"class":"product-name"}).find(href=True).get("href")
result.append(["Name: {}, Price: {}, Link: {}".format(name, price, link)])
get_details()
return result[0:3]
#print(justfone_scraper("hp laptop"))