-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
39 lines (28 loc) · 1.04 KB
/
test.py
File metadata and controls
39 lines (28 loc) · 1.04 KB
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
31
32
33
34
35
36
37
38
39
import bs4
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"
# Open Connection Grab Page
uClient = uReq(my_url)
page_html = uClient.read()
# Close Connection
uClient.close()
# HTML Pass
page_soup = soup(page_html, "html.parser")
# Grab Each item
containers = page_soup.findAll("div",{"class":"item-container"})
filename = "procuct.csv"
f = open(filename, "w")
headers = "brand, procuct_name, shipping\n"
f.write(headers)
for container in containers:
brand = container.div.div.a.img["title"]
title_container = container.findAll("a",{"class":"item-title"})
procuct_name = title_container[0].text
shipping_container = container.findAll("li", {"class":"price-ship"})
shipping = shipping_container[0].text.strip()
# print("brand" + brand)
# print("procuct_name" + procuct_name)
# print("shipping" + shipping)
f.write(brand.replace(",", "|") + "," + procuct_name.replace(",", "|") + "," + shipping.replace(",", "|") + "\n")
f.close()