试图只抓住“大使呼叫王牌无能”,但我似乎不能落地在那个领域。我试着拉出"h2“和类,以及”强标签,但似乎找不到任何东西。下面的代码我把它留在原处,这是我唯一能显示的东西。
soup = BeautifulSoup(data.text,'html.parser')
for rows in soup.find_all('li'):
for x in soup.findChildren('div'):
print(x)
发布于 2019-07-07 15:47:34
页面动态加载数据。如果您检查页面正在向哪些URL发出请求(例如,在Firefox开发者工具中),你会发现数据在不同的url中。不幸的是,这个url (https://edition.cnn.com/data/ocs/section/index.html:intl_homepage1-zone-1/views/zones/common/zone-manager.izl
)是动态构建的:
import requests
from bs4 import BeautifulSoup
url = 'https://edition.cnn.com/data/ocs/section/index.html:intl_homepage1-zone-1/views/zones/common/zone-manager.izl'
soup = BeautifulSoup(requests.get(url).text, 'lxml')
print(soup.h2.text)
打印:
UK ambassador calls Trump 'inept' and 'insecure'
https://stackoverflow.com/questions/56920110
复制相似问题