【发布时间】:2018-10-14 15:19:06
【问题描述】:
我试图在this URL 中获取列表的标题,但此代码返回无。
import requests
from bs4 import BeautifulSoup
# get the data
data = requests.get('https://www.lamudi.com.ph/metro-manila/makati/condominium/buy/')
# Update Header
headers = requests.utils.default_headers()
headers.update({
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0)
Gecko/20100101 Firefox/31.0',
})
# load data into bs4
soup = BeautifulSoup(data.text, 'html.parser')
# We need to extract all the data in this div: <div
class="ListingCell-KeyInfo-title" ..>
listingsTitle = soup.find('div', { 'class': 'ListingCell-KeyInfo-title'})
print(listingsTitle)
知道为什么吗?
谢谢
【问题讨论】:
-
在创建的汤中,没有类“ListingCell-KeyInfo-title”的 div,正如@Bob 在下面的回答中所说,因为该网站将您视为机器人,它可能已经删除了一些信息
-
爬取这个网站比你想象的要难
-
看起来是这样 :(
标签: python selenium beautifulsoup