Question

I want to print only line containing --> REQUIRES="berusky-data"

I try this but not work :

import urllib2
import re

f = urllib2.urlopen('http://slackbuilds.org/slackbuilds/14.1/games/berusk/berusky.info')
r = f.read()


for line in r:
    if "REQUIRES" in r:
          print line,
Was it helpful?

Solution

Use splitlines() for splitting the data by new-lines and check if REQUIRES string is in line:

for line in r.splitlines():
    if "REQUIRES" in line:
          print line,

Demo:

>>> import urllib2
>>> f = urllib2.urlopen('http://slackbuilds.org/slackbuilds/14.1/games/berusky/berusky.info')
>>> r = f.read()
>>> for line in r.splitlines():
...     if "REQUIRES" in line:
...         print line,
... 
REQUIRES="berusky-data"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top