简体   繁体   中英

Parenthesis in Python Yield statement

Im trying to set up a table to display some information on a webpage using yield. I cant get around the parenthesis for grid container so its not returning the whole code. Any way around this using yield? Or do i need another method altogether?

yield " <div class="grid-container"> ".encode('utf-8')

I was using a <table> but I didnt like the formatting, so I wanted to try grid-container. Its a webscraper using BeautifulSoup. Here is some of the information going to the table

            yield "<div class="grid-container">".encode('utf-8')
            for div in soup.findAll('div', attrs={'class':"col-md-10"}):
                yield "<tr>".encode('utf-8')
                for name in div.findAll('div', attrs={'name':"label-Address"}):
                     yield "<td>{}</td>".format(name.text).encode('utf-8')
                yield "</tr>".encode('utf-8')
                yield "<tr>".encode('utf-8')
                for name in div.findAll('div', attrs={'name':"label-ScheduledDate"}):
                     yield "<td>{}</td>".format(name.text).encode('utf-8')
                yield "</tr>".encode('utf-8')
                yield "<tr>".encode('utf-8')
                for name in div.findAll('div', attrs={'name':"label-CaseNumber"}):
                     yield "<th>{}</th>".format(name.text).encode('utf-8')

我可以看到一个语法错误,因为您使用了两次引号,您应该像这样更正它:

yield " <div class='grid-container'> ".encode('utf-8')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM