easyspider
Posted sky-ai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了easyspider相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*- """ Created on Fri Aug 18 15:58:13 2017 @author: JClian """ import re import bs4 import urllib.request from bs4 import BeautifulSoup import urllib.parse import sys search_item = input("Enter what you want(Enter ‘out‘ to exit):") while search_item != ‘out‘: if search_item == ‘out‘: exit(0) print("please wait...") try: url = ‘https://baike.baidu.com/item/‘+urllib.parse.quote(search_item) html = urllib.request.urlopen(url) content = html.read().decode(‘utf-8‘) html.close() soup = BeautifulSoup(content, "lxml") text = soup.find(‘div‘, class_="lemma-summary").children print("search result:") for x in text: word = re.sub(re.compile(r"<(.+?)>"),‘‘,str(x)) words = re.sub(re.compile(r"[(.+?)]"),‘‘,word) print(words,‘ ‘) except AttributeError: print("Failed!Please enter more in details!") search_item = input("Enter what you want(Enter ‘out‘ to exit):") --------------------- 作者:剑与星辰 来源:CSDN 原文:https://blog.csdn.net/jclian91/article/details/77387842 版权声明:本文为博主原创文章,转载请附上博文链接!
以上是关于easyspider的主要内容,如果未能解决你的问题,请参考以下文章