Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
847 views
in Technique[技术] by (71.8m points)

web scraping - How to scrape phone no using python when it show after clicked

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Phone number exists in page source already. There is a script in page source starting with window.__INITIAL_STATE__, it contains an object having data against multiple providers so you can get phone number for all of them from here or simply load this object in json and on basis of store as a key, get phone number against that store


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...