无法在带有bs4的标记中获取特定的href链接

byqmnocz  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(244)
import bs4
import requests
import re

r = requests.get('https://www.the961.com/latest-news/lebanon-news/').text

soup = bs4.BeautifulSoup(r, 'lxml')

for article in soup.find_all('article'):

    title = article.h3.text
    print(title)

    date = soup.find('span', class_='byline-part date').text
    print(date)

//这个返回为none,但当它工作时,它返回整个a标记,但我只希望它只返回链接本身。

link = soup.find('a', class_='title', href=True)    
    print(link)

    author = soup.find('span', class_="byline-part author").text
    print(author)
kuuvgm7e

kuuvgm7e1#

link = soup.find('h3', class_='title').a['href']

相关问题