我试图从下一页抓取新闻内容,但没有成功。https://www.business-humanrights.org/en/latest-news/?&search=nike
我已经尝试过Beautifulsoup:
r = requests.get("https://www.business-humanrights.org/en/latest-news/?&search=nike")
soup = BeautifulSoup(r.content, 'lxml')
soup
但是我要查找的内容-标记为div class ='card__content'的新闻内容不会出现在汤输出中。
我也检查了一下,但是找不到要切换到的帧。
最后,我尝试使用phantomjs和以下代码,但未成功:
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = "https://www.business-humanrights.org/en/latest-news/?&search=nike"
driver = webdriver.PhantomJS(executable_path= '~\Chromedriver\phantomjs-2.1.1-windows\bin\phantomjs.exe')
driver.get(url)
time.sleep(7)
page = driver.page_source
driver.quit()
soup = BeautifulSoup(page, 'html.parser')
container = soup.find_all('div', attrs={
'class':'card__content'})
print(container)
我没有其他选择,有人可以帮忙吗?
使用API
import requests
r = requests.get("https://www.business-humanrights.org/en/api/internal/explore/?format=json&search=nike")
print(r.json())
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句