Not acting cod python programmer does not

83 views Asked by At

At the outset, I would like to emphasize that I am not a programmer.


I have already written this code but I can not run it. I work with Visual Studio 2013, I have the following problems:

  • print "Beginning %s" % tag --- invalid syntax

  • print sou*p*.find('div', {'id': 'bar'}).p.text ----- invalid syntax

This is code was written by me. It is designed to retrieve the contents of the selected tag.

from bs4 import BeautifulSoup
from HTMLParser import HTMLParser
import urllib

class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print "Beginning %s" % tag
    def handle_endtag(self, tag): 
        print "End %s tag" % tag
    def handledata(self, data):
        print "Data %s" % data
p = MyHTMLParser()
input = urllib.urlopen('http://php.com')
html = input.read()
input.close()
soup = BeautifulSoup(p.feed(html))
print soup.find('div', {'id': 'bar'}).p.text
0

There are 0 answers