为什么我在尝试刮下一个网页后会得到一个空列表?

2024-06-07 05:49:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从以下住房网站上搜集地址:https://www.point2homes.com/CA/Real-Estate-Listings/ON/Brampton.html

这是我使用的代码

import requests
from bs4 import BeautifulSoup
import pandas as pd
import lxml




source=requests.get('https://www.point2homes.com/CA/Real-Estate-Listings/ON/Brampton.html')
soup=BeautifulSoup(source.text,'lxml')
match=soup.find_all('div',class_='address-container')
address=[]
for i in match:
    address.append(i.text)

然后,当我打印地址时,我得到一个空列表。任何帮助都将不胜感激


Tags: httpsimportcomonaddress地址htmlwww
1条回答
网友
1楼 · 发布于 2024-06-07 05:49:12

该网站正在阻止该网页被废弃

它受这个CDNhttps://www.imperva.com/保护

我不知道有什么方法可以绕过这个

注意:他们不允许这样做是有原因的。我不是法律专家,但在尝试任何其他方法之前,我会检查这是否合法。特别是如果你打算用这个作为商业理由

相关问题 更多 >