2 回答

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
試試這個(gè)代碼
import requests
def test():
url = 'https://www.pagesjaunes.ca/search/si/1/electricien/Montreal+QC'
r = requests.get(url)
soup = BeautifulSoup(r.text)
name=soup.find_all("a",{"class":"listing__name--link listing__link jsListingName"})
for i in name:
# phone=i.a.get("data-phone")
name=i.text
print(name) ```

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊
用這個(gè)改變你的湯,也為循環(huán)...
from bs4 import BeautifulSoup
import requests
def test():
url = 'https://www.pagesjaunes.ca/search/si/1/electricien/Montreal+QC'
r = requests.get(url)
# change this
soup = BeautifulSoup(r.content, 'html.parser')
name=soup.find_all("a", {"class":"listing__name--link listing__link jsListingName"})
for i in name:
# change this
name = i.text
print(name)
test()
添加回答
舉報(bào)