R
R
Ruslan Ezhgurov2015-10-27 23:24:27
Python
Ruslan Ezhgurov, 2015-10-27 23:24:27

How to get href attribute value from 'a' tag via BeautifulSoup functions?

I am writing a parser, at this stage there is a function

def parse(html):
  soup = BeautifulSoup(html)
  quests = []
  div = soup.find('div', class_='container-fluid cols_table show_visited')
  for row in div.find_all('div', 'row'):
    cols = row.find_all('div', 'col-sm-7')
    a = cols[0].find('a', class_='title')
    quests.append({
      'title': a.text,
      'urls': a.href
    })
  for quest in quests:
    print(quest)

What is the correct way to access the value of the href element? I can't find anything useful in the documentation

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2015-10-27
@Oyaseo

like so
stackoverflow.com/questions/19983165/parse-href-at...
why don't you want lxml and xpath ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question