-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebsite_Scapper.py
29 lines (20 loc) · 996 Bytes
/
Website_Scapper.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
29
import encodings
from lib2to3.pgen2.token import NEWLINE
import requests
from bs4 import BeautifulSoup
from csv import writer
url = "my_url"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
lists = soup.find_all('div', class_="result_container")
with open('My_file_name.csv', 'w', encoding='utf8', newline='') as f:
thewriter = writer(f)
header = ['Name', 'Location', 'Owner', 'Contact']
thewriter.writerow(header)
for list in lists:
name = list.find('div', class_="result_container--right-title").text.replace('\n', '')
location = list.find('div', class_="result_container--right-location").text.replace('\n', '')
owner = list.find('div', class_="result_container--right-contactname").text.replace('\n', '')
contact = list.find('div', class_="result_container--right-contactno").text.replace('\n', '')
info = [name, location, owner, contact]
thewriter.writerow(info)