我是靠谱客的博主 激昂西装,这篇文章主要介绍python3.7不能用_我用的python3.7环境,html.parser解析器无法解析,也不报错?怎么回事?...,现在分享给大家,希望可以做个参考。

from bs4 import BeautifulSoup

import re

from urllib.parse import urlparse

class HtmlParser(object):

def _get_new_urls(self, url, soup):

new_urls = set()

links = soup.find_all('a',href=re.compile(r"item/d"))

for link in links:

new_url = link['href']

new_full_url = urlparse.urljoin(url,new_url)

new_urls.add(new_full_url)

return new_urls

def _get_new_data(self, url, soup):

res_data = {}

res_data['url'] = url

title_node = soup.find('dd',class_="lemmaWgt-lemmaTitle-title").find('h1')

res_data['title'] = title_node.get_text()

summary_node = soup.find('dev',class_="lemma-summary")

res_data['summary'] = summary_node.get_text()

return res_data

def parse(self, url, html_cont):

if url is None or html_cont is None:

return

soup = BeautifulSoup(html_cont,'html.parser')

new_urls = self._get_new_urls(url,soup)

new_data = self._get_new_data(url,soup)

return new_urls,new_data

最后

以上就是激昂西装最近收集整理的关于python3.7不能用_我用的python3.7环境,html.parser解析器无法解析,也不报错?怎么回事?...的全部内容,更多相关python3.7不能用_我用内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(104)

评论列表共有 0 条评论

立即
投稿
返回
顶部