0

Hi I'm running python regular expression to extract some data from news pages, however when it is displayed the code produces brackets and apostrophes in the output. For example this is my code:

description_title = findall('<item>[\s]*<title[^>]*>(.*?)<\/title>[\s]*<description>', html_source)[:1]
        news_file.write('<h3 align="Center">' + str(description_title) + ": " + '</h3\n>')

but this code creates the output of ['Technology']:, ['Finance']: but i want Technology, Finance without the [''] around it.

Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43
Sam
  • 89
  • 1
  • 1
  • 11

1 Answers1

1

By using str, you're printing a Python string representation of description_title (which is a list of length 1). Try without the str:

'<h3 align="Center">' + description_title[0] + ": " + '</h3\n>'
wildwilhelm
  • 4,809
  • 1
  • 19
  • 24
  • 3
    If fact, `str` is not defined, in that peculiar case it calls `repr`. Which returns the string representation of a Python `list`. – Laurent LAPORTE Oct 08 '16 at 13:26