Browse Source

Added function to write data to csv file

pull/1/head
Ravi Shah 5 years ago
parent
commit
246ad46033
  1. 115
      list.csv
  2. 15
      scraper.py

115
list.csv

@ -0,0 +1,115 @@
Manufacturer,Model,Score
iPhone,12 Pro,6
Microsoft,Surface Duo,2
Samsung,Galaxy Note 20 Ultra,3
iPhone,SE 2020,6
Samsung,Galaxy A51,4
Samsung,Galaxy S20 Ultra,3
Samsung,Galaxy Z Flip,2
Motorola,razr,1
Google,Pixel 4 XL,4
iPhone,11,6
iPhone,11 Pro Max,6
Fairphone,3,10
Samsung,Galaxy Note10 Plus 5G,3
Shift,6m,9
Huawei,Mate 20 X 5G,4
Google,Pixel 3a XL,6
Google,Pixel 3a,6
Samsung,Galaxy Fold,2
Samsung,Galaxy S10,3
Huawei,Mate 20 Pro,4
iPhone,XR,6
Google,Pixel 3 XL,4
Google,Pixel 3,4
iPhone,XS,6
LG,G7 Thin Q,4
OnePlus,6,5
Huawei,P20 Pro,4
Samsung,Galaxy S9,4
Samsung,Galaxy S9 Plus,4
iPhone,X,6
Google,Pixel 2 XL,6
Google,Pixel 2,6
Huawei,Mate 10 Pro,4
iPhone,8 Plus,6
iPhone,8,6
Samsung,Galaxy Note8,4
Essential,Phone,1
Samsung,Galaxy Note Fan Edition,4
OnePlus,5,7
Samsung,Galaxy S8,4
Samsung,Galaxy S8 Plus,4
LG,G6,5
Huawei,Mate 9,5
Google,Pixel,7
Google,Pixel XL,7
iPhone,7,7
iPhone,7 Plus,7
Sony,Xperia X Compact,6
Moto,Z,7
Samsung,Galaxy Note7,4
Asus,Zenfone 3 Max,6
Meizu,MX6,7
LG,G5,8
Vivo,X7 Plus,7
Vivo,X7,6
Huawei,P9,7
Xiaomi,Mi 5,6
iPhone,SE,6
Oppo,R9m,7
Samsung,Galaxy S7 Edge,3
Samsung,Galaxy S7,3
Lenovo,K5 Note,6
Fairphone,2,10
Huawei,Mate 8,6
Xiaomi,Redmi Note 3,8
Wiko,Pulp 4G Phone,7
iPhone,6s,7
iPhone,6s Plus,7
Nexus,5X,7
Nexus,6P,2
OnePlus,2,7
Shift,5.1,6
LG,G4,8
Samsung,Galaxy S6,4
Samsung,Galaxy S6 Edge,3
HTC,One M9,2
Nexus,6,7
iPhone,6,7
iPhone,6 Plus,7
Samsung,Galaxy Alpha,5
Amazon,Fire Phone,3
Samsung,Galaxy S5 Mini,5
OnePlus,One,5
Samsung,Galaxy S5,5
HTC,One M8,2
Fairphone,1,7
Nexus,5,8
iPhone,5s,6
iPhone,5c,6
Motorola,Moto X 1st Generation,7
Samsung,Galaxy S4,8
HTC,One,1
BlackBerry,Z10,8
Nexus,4,7
Samsung,Galaxy Note II,8
iPhone,5,7
Samsung,Galaxy S III,8
Motorola,Droid 4,4
Samsung,Galaxy Nexus,7
Motorola,Droid RAZR,4
iPhone,4S,6
Samsung,Galaxy Note,8
Motorola,Droid Bionic,9
Motorola,Droid 3,6
Samsung,Galaxy S II,8
Samsung,Galaxy S 4G,6
iPhone,4 Verizon,6
Motorola,Atrix 4G,9
Nexus,S,7
HTC,Surround,5
Nokia,N8,8
iPhone,3GS,7
iPhone,3G,7
iPhone,1st Generation,2
1 Manufacturer Model Score
2 iPhone 12 Pro 6
3 Microsoft Surface Duo 2
4 Samsung Galaxy Note 20 Ultra 3
5 iPhone SE 2020 6
6 Samsung Galaxy A51 4
7 Samsung Galaxy S20 Ultra 3
8 Samsung Galaxy Z Flip 2
9 Motorola razr 1
10 Google Pixel 4 XL 4
11 iPhone 11 6
12 iPhone 11 Pro Max 6
13 Fairphone 3 10
14 Samsung Galaxy Note10 Plus 5G 3
15 Shift 6m 9
16 Huawei Mate 20 X 5G 4
17 Google Pixel 3a XL 6
18 Google Pixel 3a 6
19 Samsung Galaxy Fold 2
20 Samsung Galaxy S10 3
21 Huawei Mate 20 Pro 4
22 iPhone XR 6
23 Google Pixel 3 XL 4
24 Google Pixel 3 4
25 iPhone XS 6
26 LG G7 Thin Q 4
27 OnePlus 6 5
28 Huawei P20 Pro 4
29 Samsung Galaxy S9 4
30 Samsung Galaxy S9 Plus 4
31 iPhone X 6
32 Google Pixel 2 XL 6
33 Google Pixel 2 6
34 Huawei Mate 10 Pro 4
35 iPhone 8 Plus 6
36 iPhone 8 6
37 Samsung Galaxy Note8 4
38 Essential Phone 1
39 Samsung Galaxy Note Fan Edition 4
40 OnePlus 5 7
41 Samsung Galaxy S8 4
42 Samsung Galaxy S8 Plus 4
43 LG G6 5
44 Huawei Mate 9 5
45 Google Pixel 7
46 Google Pixel XL 7
47 iPhone 7 7
48 iPhone 7 Plus 7
49 Sony Xperia X Compact 6
50 Moto Z 7
51 Samsung Galaxy Note7 4
52 Asus Zenfone 3 Max 6
53 Meizu MX6 7
54 LG G5 8
55 Vivo X7 Plus 7
56 Vivo X7 6
57 Huawei P9 7
58 Xiaomi Mi 5 6
59 iPhone SE 6
60 Oppo R9m 7
61 Samsung Galaxy S7 Edge 3
62 Samsung Galaxy S7 3
63 Lenovo K5 Note 6
64 Fairphone 2 10
65 Huawei Mate 8 6
66 Xiaomi Redmi Note 3 8
67 Wiko Pulp 4G Phone 7
68 iPhone 6s 7
69 iPhone 6s Plus 7
70 Nexus 5X 7
71 Nexus 6P 2
72 OnePlus 2 7
73 Shift 5.1 6
74 LG G4 8
75 Samsung Galaxy S6 4
76 Samsung Galaxy S6 Edge 3
77 HTC One M9 2
78 Nexus 6 7
79 iPhone 6 7
80 iPhone 6 Plus 7
81 Samsung Galaxy Alpha 5
82 Amazon Fire Phone 3
83 Samsung Galaxy S5 Mini 5
84 OnePlus One 5
85 Samsung Galaxy S5 5
86 HTC One M8 2
87 Fairphone 1 7
88 Nexus 5 8
89 iPhone 5s 6
90 iPhone 5c 6
91 Motorola Moto X 1st Generation 7
92 Samsung Galaxy S4 8
93 HTC One 1
94 BlackBerry Z10 8
95 Nexus 4 7
96 Samsung Galaxy Note II 8
97 iPhone 5 7
98 Samsung Galaxy S III 8
99 Motorola Droid 4 4
100 Samsung Galaxy Nexus 7
101 Motorola Droid RAZR 4
102 iPhone 4S 6
103 Samsung Galaxy Note 8
104 Motorola Droid Bionic 9
105 Motorola Droid 3 6
106 Samsung Galaxy S II 8
107 Samsung Galaxy S 4G 6
108 iPhone 4 Verizon 6
109 Motorola Atrix 4G 9
110 Nexus S 7
111 HTC Surround 5
112 Nokia N8 8
113 iPhone 3GS 7
114 iPhone 3G 7
115 iPhone 1st Generation 2

15
scraper.py

@ -2,6 +2,7 @@ import time
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests import requests
import re import re
import csv
def get_device_manufacturers(device_names): def get_device_manufacturers(device_names):
list_of_manufacturers_without_tags = [] list_of_manufacturers_without_tags = []
@ -38,7 +39,19 @@ def data_from_each(list_of_manufacturers_without_tags, list_of_models_without_ta
print(list_of_manufacturers_without_tags[j], list_of_models_without_tags[j], list_of_scores_without_tag[j]) print(list_of_manufacturers_without_tags[j], list_of_models_without_tags[j], list_of_scores_without_tag[j])
j = j + 1 j = j + 1
def insert_into_csv(list_of_manufacturers_without_tags, list_of_models_without_tags, list_of_scores_without_tag):
j = 0
for i in list_of_manufacturers_without_tags:
with open('list.csv', 'a', newline='') as file:
writer = csv.writer(file)
print(list_of_manufacturers_without_tags[j], list_of_models_without_tags[j], list_of_scores_without_tag[j])
writer.writerow([list_of_manufacturers_without_tags[j], list_of_models_without_tags[j], list_of_scores_without_tag[j]])
j = j + 1
def main(): def main():
with open('list.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Manufacturer", "Model", "Score"])
link = "https://www.ifixit.com/smartphone-repairability" link = "https://www.ifixit.com/smartphone-repairability"
page = requests.get(link) page = requests.get(link)
soup = BeautifulSoup(page.content, 'html.parser') soup = BeautifulSoup(page.content, 'html.parser')
@ -47,7 +60,7 @@ def main():
list_of_manufacturers_without_tags = get_device_manufacturers(device_names) list_of_manufacturers_without_tags = get_device_manufacturers(device_names)
list_of_models_without_tags = get_device_models(device_names, soup) list_of_models_without_tags = get_device_models(device_names, soup)
list_of_scores_without_tag = format_device_scores(device_scores, soup) list_of_scores_without_tag = format_device_scores(device_scores, soup)
data_from_each(list_of_manufacturers_without_tags, list_of_models_without_tags, list_of_scores_without_tag)
insert_into_csv(list_of_manufacturers_without_tags, list_of_models_without_tags, list_of_scores_without_tag)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Loading…
Cancel
Save