Isolated Gamer
Isolated Gamer

Reputation: 65

Cannot get specific href link in a tag with bs4

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)

// This returns as None, but when it does work it returns the whole a tag, but I only want it to return only the link itself.

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

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

Upvotes: 0

Views: 37

Answers (1)

Daniel Konstantinov
Daniel Konstantinov

Reputation: 411

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

Upvotes: 2

Related Questions