原始代码:
soup = BeautifulSoup(result, 'html.parser') content_list = soup.find_all('p', attrs={"class": "art_p"}) content = '<br/>'.join(content_list)
报错内容是:
Traceback (most recent call last): File "G:/squid_frame/app_spider/spider_3_sina/sina_2_content_spider.py", line 169, in <module> sina_content_spider(item=item) File "G:/squid_frame/app_spider/spider_3_sina/sina_2_content_spider.py", line 107, in sina_content_spider content = '<br/>'.join(content_list) TypeError: sequence item 0: expected string, Tag found
解决办法:
soup = BeautifulSoup(result, 'html.parser') content_list = soup.find_all('p', attrs={"class": "art_p"}) content = ' <br>'.join(str(ii) for ii in content_list)