本文整理汇总了Python中bs4.CData方法的典型用法代码示例。如果您正苦于以下问题:Python bs4.CData方法的具体用法?Python bs4.CData怎么用?Python bs4.CData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bs4
的用法示例。
在下文中一共展示了bs4.CData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_companies
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def check_companies(session, sessionData):
r = session.get(ERP_COMPANIES_URL, **req_args)
companies_list = bs(r.text, 'html.parser')
companies = []
for row in companies_list.find_all('row'):
company = {}
cds = filter(lambda x: isinstance(x, CData), row.find_all(text=True))
a = bs(cds[0].string, 'html.parser').find_all('a')[0]
company['name'], company['name_link'] = a.attrs['title'], a.attrs['onclick']
a = bs(cds[3].string, 'html.parser').find_all('a')[0]
company['job'], company['job_link'] = a.attrs['title'], a.attrs['onclick']
a = bs(cds[7].string, 'html.parser').find_all('a')[0]
company['description_link'] = a.attrs['onclick']
company['start_date'], company['end_date'] = cds[9], cds[10]
companies.append(company)
handle_companies_diff(companies)
示例2: is_cdata
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def is_cdata(obj):
"""Is CDATA."""
return isinstance(obj, bs4.CData)
示例3: is_special_string
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def is_special_string(obj):
"""Is special string."""
return isinstance(obj, (bs4.Comment, bs4.Declaration, bs4.CData, bs4.ProcessingInstruction, bs4.Doctype))
示例4: is_special_string
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def is_special_string(obj):
"""Is special string."""
import bs4
return isinstance(obj, (bs4.Comment, bs4.Declaration, bs4.CData, bs4.ProcessingInstruction))
示例5: is_cdata
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def is_cdata(obj):
"""Is CDATA."""
import bs4
return isinstance(obj, bs4.CData)
示例6: is_special_string
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def is_special_string(obj):
"""Is special string."""
import bs4
return isinstance(obj, (bs4.Comment, bs4.Declaration, bs4.CData, bs4.ProcessingInstruction, bs4.Doctype))
示例7: check_notices
# 需要导入模块: import bs4 [as 别名]
# 或者: from bs4 import CData [as 别名]
def check_notices(session, sessionData):
r = session.get(ERP_NOTICEBOARD_URL, **req_args)
r = session.get(ERP_NOTICES_URL, **req_args)
print "ERP and TNP login completed!"
notices_list = bs(r.text, 'html.parser')
print "Total number of notices fetched: %d" % len(notices_list.find_all('row'))
notices = []
# Only check the first 50 notices
for row in notices_list.find_all('row')[:NUM_NOTICES_DIFFED]:
notice = {}
cds = filter(lambda x: isinstance(x, CData), row.find_all(text=True))
notice['subject'] = cds[2].string
notice['company'] = cds[3].string
a = bs(cds[4].string, 'html.parser').find_all('a')[0]
try :
m = re.search(r'ViewNotice\("(.+?)","(.+?)"\)', a.attrs['onclick'])
except KeyError :
print("Poorly formatted notice found")
continue
year, id_ = m.group(1), m.group(2)
content = bs(session.get(ERP_NOTICE_CONTENT_URL % (year, id_)).text, 'html.parser')
content_div = bs.find_all(content, 'div', {'id': 'printableArea'})[0]
notice['text'] = content_div.decode_contents(formatter='html')
notice['time'] = cds[6].string
a = bs(cds[7].string, 'html.parser').find_all('a')[0]
if a.attrs['title'] == 'Download':
onclick = a.attrs['onclick']
m = re.search(r'TPNotice\("(.+)"\)', onclick)
notice['attachment_url'] = ERP_ATTACHMENT_URL + m.group(1)
r = session.get(notice['attachment_url'], stream=True)
r.raw.decode_content = True
hash_ = hashlib.md5()
notice['attachment_raw'] = b""
for chunk in r.iter_content(4096):
notice['attachment_raw'] += chunk
hash_.update(chunk)
notice['attachment_md5'] = hash_.hexdigest()
notices.append(notice)
handle_notices_diff(notices)