-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebscraping.py
More file actions
33 lines (22 loc) · 838 Bytes
/
Copy pathwebscraping.py
File metadata and controls
33 lines (22 loc) · 838 Bytes
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
29
30
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as ureq
myUrl="https://www.flipkart.com/search?q=iphone&otracker=start&as-show&as=off"
uClient = ureq(myUrl)
page_html = uClient.read()
#print(page_html)
uClient.close()
page_soup= soup(page_html,"html.parser")
#print(page_soup)
containers = page_soup.findAll("div",{"class":"col col-5-12 _2o7WAb"})
#print(len(containers))
#print(soup.prettify(containers[0]))
container = containers[0]
price = container.findAll("div",{"class":"_6BWGkk"})
#print(price[0].text)
for container in containers:
price_cont = container.findAll("div",{"class":"_6BWGkk"})
pricer = price_cont[0].text.strip()
print(pricer)
container1 = page_soup.findAll("div",{"class":"col col-7-12"})
rating = container1[0].findAll('div',{'class':'hGSR34'})
print(rating[0].text)