Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
941 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...