使用Beautifulsoup错误

时间:2018-11-03 21:30:09

标签: python json parsing beautifulsoup

晚上好,Stackoverflow叉,

我是Python的新手,并试图去读研究生学校以进一步了解它。 最近,我认识了一个很棒的加载项,即BeauifulSoup。 我试图从房地产网站“ Nestio”中解析位置数据。

据我了解,我进行了如下编码。

from bs4 import BeautifulSoup
import requests

source = requests.get('https://nestiolistings.com/listings/?listing_type=10&min_price=2500&max_price=3000').text

soup = BeautifulSoup(source, 'lxml')
address = soup.find_all('span', class_ = 'building-title-content')

print(address)

我通过“检查”从网站获取的代码是

enter image description here

运行代码后,它仅显示“无” ...

我之所以无法得到结果,可能是因为

-信息来自href?还是嵌套太多?

我也尝试从第1页到第53页获取信息。 有人告诉我我需要使用“ Json”。

import requests
count = 0
for i in range(53):
    count+=1
    link = 'https://nestiolistings.com/listings/?listing_type=10&min_price=2500&max_price=3000&pageNumber='+str(count)
    req = requests.get(link)
    for i in req.json()['building-title-content']:
        address = (i['building-title-content'])
        print ('Address:', address)

所以我也尝试了Json代码,但这似乎不起作用...

有人知道如何解决此问题吗? 提前欣赏。 我已经为这个问题苦苦挣扎了一个月,但仍然没有任何线索可以解决这个问题...

0 个答案:

没有答案