我用的是漂亮的汤4.4和python 3.6.6。我已经提取了所有链接,但是我无法打印出包含
'class':[''u self']
这是从链接列表中获取的完整链接。
{'href': 'https://www.racingnsw.com.au/news/latest-racing-news/highway-sixtysix-on-right-route/', 'class': ['_self'], 'target': '_self'}
虽然它看起来像上的BS4文档,但我无法获得正确的语法。
attributes
.
import requests as req
import json
from bs4 import BeautifulSoup
url = req.get(
'https://www.racingnsw.com.au/media-news-premierships/latest-news/')
data = url.content
soup = BeautifulSoup(data, "html.parser")
links = soup.find_all('a')
for item in links:
print(item['class']='self')