这是我的代码:
for x in header:
testvar = x.find('strong')
testvar2 = testvar.contents[0]
print(testvar2)
这是我的追溯:
Traceback (most recent call last):
File "S:\Personal Folders\Andy\Python Projects\Salesforce BZ API\Automated Reports.py", line 38, in <module>
print(testvar2)
File "C:\Python27\lib\idlelib\rpc.py", line 595, in __call__
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
File "C:\Python27\lib\idlelib\rpc.py", line 210, in remotecall
seq = self.asynccall(oid, methodname, args, kwargs)
File "C:\Python27\lib\idlelib\rpc.py", line 225, in asynccall
self.putmessage((seq, request))
File "C:\Python27\lib\idlelib\rpc.py", line 324, in putmessage
s = pickle.dumps(message)
File "C:\Python27\lib\copy_reg.py", line 74, in _reduce_ex
getstate = self.__getstate__
File "build\bdist.win32\egg\BeautifulSoup.py", line 655, in __getattr__
raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__, tag)
RuntimeError: maximum recursion depth exceeded while getting the str of an object
我不确定为什么它不会让我选择强标签的内容,任何想法?我也无法将这些值恢复到列表标题中。
以下是生成标题的完整代码:
from __future__ import division
#from __future__ import unicode_literals
from __future__ import print_function
import spynner
from BeautifulSoup import BeautifulSoup
#Loading up Salesforce
br = spynner.Browser()
#br.debug_level = spynner.DEBUG
br.create_webview()
br.show()
br.set_html_parser(BeautifulSoup)
br.load("https://login.salesforce.com/")
br.fill("input[name=username]", "USERNAME")
br.fill("input[name=pw]", "PASSWORD")
br.click("input[name=Login]", wait_load=True)
br.load("https://na8.salesforce.com/00OC0000004jUDu")
html = br.soup()
html = [str(x) for x in html]
html = ''.join(html)
html = BeautifulSoup(html)
header = html.find('form', {'id': 'report'})
header = header.find('div', {'class': 'bGeneratedReport'})
header = header.find('div', {'class': 'reportOutput'})
header = header.find('tbody')
header = header.findAll('th')