我想提取公司的所有链接(不是标题)。请指导我!谢谢! 这是网页的网址:https://hipages.com.au/find/antenna_services/nsw/sydney
这是我的代码:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
答案 0 :(得分:1)
import requests
from bs4 import BeautifulSoup
r = requests.get("https://hipages.com.au/find/antenna_services/nsw/sydney")
soup = BeautifulSoup(r.text, 'html.parser')
for item in soup.findAll("h3", {'class': 'sc-bZQynM sc-iwsKbI dpKmnV'}):
print(f"https://hipages.com.au{item.previous_element.get('href')}")
输出:
https://hipages.com.au/connect/glencoelectricalbuildingmaintenanceairconditioningsecurityalarmscctv
https://hipages.com.au/connect/emcoelectricalservices
https://hipages.com.au/connect/abcelectricservicespl/service/126298
https://hipages.com.au/connect/ozyblindsnscreens
https://hipages.com.au/connect/samedaytvantennaservice
https://hipages.com.au/connect/langenelectricalnsw
https://hipages.com.au/connect/allprohandymanmaintenance
https://hipages.com.au/connect/amateairconditioningrefrigerationservices
https://hipages.com.au/connect/makeurmove
https://hipages.com.au/connect/uberantennas/service/184323
https://hipages.com.au/connect/cmkelectricalanddata
https://hipages.com.au/connect/antennadistributionservicesptyltd
https://hipages.com.au/connect/sydneysparky
https://hipages.com.au/connect/bluediamond
https://hipages.com.au/connect/digiproantennas
https://hipages.com.au/connect/vascom
https://hipages.com.au/connect/sparkyselectricalanddataptyltd
https://hipages.com.au/connect/prosparksolutions