此代码在python3中工作正常,并且print命令显示已通过urllib.request.urlopen传递给函数的Webside页面内容。但是,在打印完for循环后在threadworker中调用函数时,不会带回任何信息。
def meta_data(page_result):
_side = {
'expires': '',
'generator': ''
}
soup = BeautifulSoup(page_result, "lxml")
print(soup)
# get meta infos
for tag in soup.find_all('meta', attrs={'name': 'expires'}):
if 'content' in str(tag):
tag = str(tag)
tag = str(tag.split('"')[1:2])
tag = clean_string(tag)
_side['expires'] = tag
for tag in soup.find_all('meta', attrs={'name': 'generator'}):
if 'content' in str(tag):
tag = str(tag)
tag = str(tag.split('"')[1:2])
tag = clean_string(tag)
_side['generator'] = tag
return _side
有什么惊喜吗?