Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import requests
- from bs4 import BeautifulSoup
- with open('results.csv', 'w') as f:
- f.write("Bussiness Name , Phone Number, Address \n")
- raw = requests.get('https://www.yellowpages.my/listing/results.php?keyword=boutique&where=selangor&screen=1').text
- raw = raw.replace("</br>", "")
- soup = BeautifulSoup(raw, 'html.parser')
- name = soup.find_all('div', {'class' :'cbp-vm-companytext'})
- # phone = [d.find('a') for d in soup.find_all('div',{'class':'cbp-vm-cta'})]
- phone = [re.findall('\>.*?<',d.find('span')['data-content'])[0][1:][:-1] for d in soup.find_all('div',{'class':'cbp-vm-cta'})]
- # phone = soup.find_all('span', {'class': 'cbp-vm-cta'})
- # phone = [x.text.strip().split("\r\n")[-1].strip() for x in soup.find_all("div", class_='cbp-vm-cta')]
- addresses = [x.text.strip().split("\r\n")[-1].strip() for x in soup.find_all("div", class_='cbp-vm-address')]
- print(phone)
- num_page_items = len(addresses)
- with open('results.csv', 'a') as f:
- for i in range(num_page_items):
- f.write(name[i].text + "," + phone[i] + "," + addresses[i] + "," + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement