Python 建立一个房地产经纪人信息网站

Python 建立一个房地产经纪人信息网站,python,python-3.x,web-scraping,Python,Python 3.x,Web Scraping,我创建了第一个刮板,专门用来阅读phoenix realtors旗下realtor.com的第一页信息。我可以阅读和摘录第1页上的20名房地产经纪人,绝对没有问题 然而,我想增加它的趣味性,尝试阅读多页信息,我不擅长写循环,所以我转向互联网,我一直被卡住,特别是我遇到了这个错误: “第42行,请查看上一行。您的container.find()函数找不到任何东西,返回了None,它成为numberNone的值,没有任何方法或属性,这就是你的错误。是的,但是我在我的另一个scape中使用了相同的代码

我创建了第一个刮板,专门用来阅读phoenix realtors旗下realtor.com的第一页信息。我可以阅读和摘录第1页上的20名房地产经纪人,绝对没有问题

然而,我想增加它的趣味性,尝试阅读多页信息,我不擅长写循环,所以我转向互联网,我一直被卡住,特别是我遇到了这个错误:


“第42行,请查看上一行。您的
container.find()
函数找不到任何东西,返回了
None
,它成为
number
None
的值,没有任何方法或属性,这就是你的错误。是的,但是我在我的另一个scape中使用了相同的代码,没有尝试循环,它从realtor.com/realestateage获取了第一页信息nts/phoenix_az现在非常完美。当我使用realtor.com/realestateagents/phoenix_az/pg-2作为起点时,它没有返回第页上的信息。好的,马特,很抱歉,我发现了这个问题,我没有写规则跳过没有信息的内容,这样会打破循环谢谢!这回答了你的问题吗?
Below is the code i wrote trying to add a loop so i can read the first 30 pages of realtor information however i am getting a little stuck. If any of you geniuses can see what i am doing wrong it would be a great help. Here is the new code which is giving me the error stated above:

import requests
from requests import get
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup 
import numpy as np
from numpy import arange

from time import sleep
from random import randint

headers = {"Accept-Language": "en-US,en;q=0.5"}

my_url = 'https://www.realtor.com/realestateagents/phoenix_az/pg-2'

#opening up connection, grabbing the page
uClient = uReq(my_url)
#read page 
page_html = uClient.read()
#close page
uClient.close()

pages = np.arange(1, 30, 1)

for page in pages:

    page = requests.get("https://www.realtor.com/realestateagents/phoenix_az/pg-2" + str(page) + "&ref_=adv_nxt", headers=headers)


#html parsing
page_soup = soup(page_html, "html.parser")

sleep(randint(2,10))

#finds all realtors on page 
containers = page_soup.findAll("div",{"class":"agent-list-card clearfix"})

for container in containers:
    name = container.find('div', class_='agent-name text-bold')
    agent_name = name.text.strip()

    number = container.find('div', class_='agent-phone hidden-xs hidden-xxs')
    agent_number = number.text.strip()


print("name: " + agent_name)
print("number: " + agent_number)