I want to scrape phone no but phone no only displays after clicked so please is it possible to scrape phone no directly using python?My code scrape phone no but with starr***. here is the link from where I want to scrape phone no:https://hipages.com.au/connect/abcelectricservicespl/service/126298 please guide me!
here is my code:
import requests
from bs4 import BeautifulSoup
def get_page(url):
response = requests.get(url)
if not response.ok:
print('server responded:', response.status_code)
else:
soup = BeautifulSoup(response.text, 'lxml')
return soup
def get_detail_data(soup):
try:
title = (soup.find('h1', class_="sc-AykKI",id=False).text)
except:
title = 'Empty Title'
print(title)
try:
contact_person = (soup.findAll('span', class_="Contact__Item-sc-1giw2l4-2 kBpGee",id=False)[0].text)
except:
contact_person = 'Empty Person'
print(contact_person)
try:
location = (soup.findAll('span', class_="Contact__Item-sc-1giw2l4-2 kBpGee",id=False)[1].text)
except:
location = 'Empty location'
print(location)
try:
cell = (soup.findAll('span', class_="Contact__Item-sc-1giw2l4-2 kBpGee",id=False)[2].text)
except:
cell = 'Empty Cell No'
print(cell)
try:
phone = (soup.findAll('span', class_="Contact__Item-sc-1giw2l4-2 kBpGee",id=False)[3].text)
except:
phone = 'Empty Phone No'
print(phone)
try:
Verify_ABN = (soup.find('p', class_="sc-AykKI").text)
except:
Verify_ABN = 'Empty Verify_ABN'
print(Verify_ABN)
try:
ABN = (soup.find('div', class_="box__Box-sc-1u3aqjl-0").find('a'))
except:
ABN = 'Empty ABN'
print(ABN)
def main():
#get data of detail page
url = "https://hipages.com.au/connect/abcelectricservicespl/service/126298"
#get_page(url)
get_detail_data(get_page(url))
if __name__ == '__main__':
main()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…