import requests
from bs4 import BeautifulSoup
url = 'https://www.yellowpages.ca/search/si/1/coffee/Toronto+ON'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
for listing in soup.find_all('div', class_='listings'):
phone = listing.find('div', class_='phone')
website = listing.find('div', class_='url')
if phone:
print(phone.text)
if website:
print(website.text)
我试图刮电话号码和网站地址从这个网站https://www.yellowpages.ca/search/si/1/coffee/Toronto+ON,但我的代码返回没有结果,所以我不能理解错误在哪里
1条答案
按热度按时间eagi6jfj1#
问题是你没有在响应中找到正确的标签。我修改了你的代码:
输出为: