0

from bs4 import BeautifulSoup

from urllib import urlopen

import re

b = urllib2.urlopen("http://www.apache.org")

soup = BeautifulSoup(b)

for link in soup.findAll('a'):

print " %s link.get" % ('href')

f = open("/home/apache/test/test.txt", "w")

    f.write()

    f.close()

How to save links automatically repeat??????

  • 1
    possible duplicate of [What does %s mean in Python?](http://stackoverflow.com/questions/997797/what-does-s-mean-in-python) – Shahriar Dec 15 '14 at 11:21

1 Answers1

1

It's a placeholder for formatting. It represents a string.

" %s link.get" % ('href')

is equivalent to

" " + 'href' + " link.get"

The placeholders can make things more readable, without cluttering the text with quotes and +. Though in this case, there is no variable, so it is simply

" href link.get"

However, .format() is preferred to % formatting nowadays, like

" {} link.get".format('href')
Paul Draper
  • 78,542
  • 46
  • 206
  • 285