forked from kactlabs/python-75-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebScrapping.py
More file actions
21 lines (21 loc) · 857 Bytes
/
Copy pathWebScrapping.py
File metadata and controls
21 lines (21 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from urllib.request import urlopen as ureq
from bs4 import BeautifulSoup as soup
my_url='https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38?Tpk=graphics%20card%27'
uClient=ureq(my_url)
page_html=uClient.read()
uClient.close()
page_soup=soup(page_html,"html.parser")
containers=page_soup.findAll("div",{"class":"item-container"})
filename="products.csv"
f=open(filename,"w")
headers="Brand,product_name,shipping\n"
f.write(headers)
for container in containers:
brand=container.div.div.a.img["title"]
title_cotainer=container.findAll("a",{"class":"item-title"})
product_name=title_cotainer[0].text
shipping_container=container.findAll("li",{"class":"price-ship"})
shipping=shipping_container[0].text.strip()
print("brand:"+brand)
f.write(brand + "," +product_name + "," + shipping + "\n")
f.close()