Python以及PyCharm安装成功后,操作如下:

此时,代码import requests不报错了。

那么,Python 在windows上安装BeautifulSoup,怎么操作呢?

1. 打开https://www.crummy.com/software/BeautifulSoup/bs4/download/4.1/,下载

将下载的压缩包放到安装目录下:

然后,执行以下操作:

这样操作完后,再回到编译器,发现它以及暂时不报错了。

运行以下代码:

# -*- encoding=UTF-8 -*-

import requests
import random
import re
from bs4 import BeautifulSoup def qiushibaike():
content = requests.get('http://www.qiushibaike.com').content
soup = BeautifulSoup(content, 'html.parser') for div in soup.find_all('div', {'class': 'content'}):
print div.text.strip() def demo_string():
stra = 'hello world"'
print stra.capitalize()
print stra.replace('world', 'nowcoder')
strb = ' \n\rhello nowcoder \r\n '
print 0, strb
print 1, strb.lstrip()
print 2, strb.rstrip(), "xx"
strc = 'hello w'
print 3, strc.startswith('hel')
print 4, strc.endswith('x')
print 5, stra + strb + strc
print 6, len(stra), len(strb), len(strc)
print 7, 'x'.join(['a', 'b', 'c']) # StringBuilder
print 8, strc.split(' ')
print 9, strc.find('llo') def demo_operation():
print 1, 1 + 2, 5 / 2, 5 * 2, 5 - 2
print 1, 1 + 2, 5 / 2.0, 5 * 2, 5 - 2
print 2, True, not True, not False
print 3, 1 << 2, 88 >> 2 # 0x11111
print 4, 1 < 2, 5 < 3
print 5, 5 | 3, 5 & 3, 5 ^ 3 # 0x101 0x011
x = 3
y = 5.0
print x, y, type(x), type(y) def demo_buildinfunction():
print 1, max(2, 1), min(5, 3)
print 2, len('xxx'), len([1, 2, 3])
print 3, abs(-2), abs(7)
print 4, range(1, 10, 2)
# print 5, '\n'.join(dir(list))
x = 2
print x + 3
print 6, eval('x*2+4')
print 7, chr(66), ord('a')
print 8, divmod(11, 3) def demo_controlflow():
score = 65
if score > 99:
print 1, 'A'
elif score > 60:
print 2, 'B'
else:
print 3, 'C'
while score < 100:
print score
score += 10
if score > 80:
break # for (int i = 0; i < 10; ++i)
for i in range(0, 10):
if i == 0:
pass
if i == 3:
continue
if i < 5:
print i * i
if i == 7:
break # print i def demo_list():
lista = [1, 2, 3] # vector<int> ArrayList<Integer>
print 1, lista
# print dir(list)
listb = ['a', 1, 1.1]
print 2, listb
lista.extend(listb)
print 3, lista
print 4, len(lista)
print 5, 'a' in lista, 'b' in lista
lista = lista + listb
print lista
listb.insert(0, 'wwwwwww')
print listb
listb.pop(1)
print listb
listb.sort()
print listb
print listb[1], listb[2]
print listb * 2
print [0] * 10 # memset
listb.append('xxx')
print listb
listb.reverse()
print listb
t = (1, 1, 3) # pair<int, xxx>
print t
print t.count(1), len(t) def add(a, b):
return a + b def sub(a, b):
return a - b def demo_dict():
dicta = {4: 16, 1: 1, 2: 4, 3: 9, 'a': 'b'}
print 1, dicta
print 2, dicta.keys(), dicta.values()
for key, value in dicta.items():
print 3, key, value
for key in dicta.keys():
print 4, key
print 5, dicta.has_key(1), dicta.has_key(11) dictb = {'+': add, '-': sub}
print 6, dictb['+'](1, 2)
print 7, dictb.get('-')(6, 2) print 8, dictb
del dictb['+']
print 9, dictb dictb.pop('-')
print 10, dictb dictb['x'] = 'y'
print dictb
# Map.put(key, value) def demo_set():
lista = (1, 2, 3)
seta = set(lista)
print 1, seta
setb = set((2, 3, 4))
print 2, seta.intersection(setb)
print 3, seta & setb
print 4, seta | setb, seta.union(setb)
print 5, seta - setb, setb - seta
seta.add('xxx')
print 6, seta
print 7, len(seta)
print seta.isdisjoint(set(('a', 'b')))
print 8, 1 in seta class User:
type = 'USER' def __init__(self, name, uid):
self.name = name
self.uid = uid def __repr__(self):
return 'im ' + self.name + ' ' + str(self.uid)
# toString() class Guest(User):
def __repr__(self):
return 'im guest ' + self.name + ' ' + str(self.uid) class Admin(User):
type = 'ADMIN' def __init__(self, name, uid, group):
User.__init__(self, name, uid)
self.group = group '''
def __repr__(self):
return 'im admin ' + self.name + ' ' + str(self.uid) + ' ' + self.group
''' def create_user(type):
if type == 'USER':
return User('u1', 1)
elif type == 'ADMIN':
return Admin('a1', 2, 'g1')
else:
return Guest('g1', 3) def demo_object():
user1 = User('jim', 1)
print user1
guest1 = Guest('lily', 2)
print guest1
admin1 = Admin('xiangyu', 3, 'nowcoder')
print admin1
print create_user('ADMIN') def demo_exception():
try:
print 2 / 1
# print 2/0
raise Exception('Raise Error', 'XXXX')
except Exception as e:
print 'error', e
finally:
print 'clean up' def demo_random():
# random.seed(1)
# x = prex * 100007 % xxxx
# prex = x for i in range(0, 5):
print 1, random.randint(0, 100)
print 2, int(random.random() * 100)
print 3, random.choice(range(0, 100, 5))
print 4, random.sample(range(0, 100, 10), 5) lista = [1, 2, 3, 4, 5]
random.shuffle(lista)
print lista def demo_regex():
str = 'abc123def12gh15'
p1 = re.compile('[\d]+')
p2 = re.compile('\d')
print 1, p1.findall(str)
print 2, p2.findall(str) str = 'axxx@163.com,bcc@google.com,c@qq.com,d@qq.com,e@163.com'
p3 = re.compile('[\w]+@[163|qq]+\.com')
print 3, p3.findall(str) str = '<html><h>title</h><body>content</body></html>'
p4 = re.compile('<h>[^<]+</h>')
print 4, p4.findall(str)
p4 = re.compile('<h>[^<]+</h><body>[^<]+</body>')
print 5, p4.findall(str) str = 'xx2016-08-20zzz,xx2016-8-20zzz'
p5 = re.compile('\d{4}-\d{2}-\d{2}')
print p5.findall(str) if __name__ == '__main__':
# qiushibaike()
# demo_string()
# demo_operation()
# demo_buildinfunction()
# demo_controlflow()
# demo_list()
# demo_dict()
# demo_set()
# print 'hello world'
# demo_object()
# demo_exception()
#demo_random()
demo_regex() 运行结果为:

												

Python 在windows上安装BeautifulSoup和request以及小案例的更多相关文章

  1. Python在Windows上安装配置测试

    Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上.在Windows上写Python程序,放到Linux上也是能够运行的. 2.x还是3.x 目前,Python ...

  2. (三)Python在windows上安装

    1.安装2.7--进入python官网(网址百度)下载python2.7 和python3.6(很小,2个程序后缀不一样?)2.安装到c:\python----next----advanced不动-- ...

  3. python环境搭建-在Windows上安装python3.5.2

    在Windows上安装Python3.5.2 首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Python 3.5.2对应的64位安装程序或32位安装程序(网速慢的同学 ...

  4. windows上安装apache python mod_python

    综述:   windows上安装apache python mod_python的例子.教程甚至图解都不少:但作为新手还是会出错,而且一时无法快速排解. 在此笔者将根据自己的实践经验,给出几个需要注意 ...

  5. 【python安装】Windows上安装和创建python开发环境

    1. 在 windows10 上安装python开发环境 Linux和Mac OS都自带python环境,但是Windows没有,所以需要自行安装. 第1步:访问 python官网,下载Windows ...

  6. windows上安装python虚拟环境

    一.windows上安装python虚拟环境 1.安装pip install virtualenvvirtualenv --version 2.新建一个python虚拟环境virtual_env_01 ...

  7. windows上安装Anaconda和python的教程详解

    一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...

  8. Redis简介以及如何在Windows上安装Redis

    Redis简介 Redis是一个速度非常快的非关系型内存数据库. Redis提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erla ...

  9. 在windows上安装nginx

    在windows上安装nginx   最近自己也尝试了一下在windows上安装nginx,其实非常的简单,这里算是备忘一下.   首先需要到nginx的官网上下载最新版的nginx:http://n ...

随机推荐

  1. 【BZOJ1316】树上的询问 点分治+set

    [BZOJ1316]树上的询问 Description 一棵n个点的带权有根树,有p个询问,每次询问树中是否存在一条长度为Len的路径,如果是,输出Yes否输出No. Input 第一行两个整数n, ...

  2. WebService 简单应用

    Web服务全称:XML Web Service,是一种可编程的应用程序逻辑组件,它可以在Internet或企业网的Web应用程序之间共享.Web服务被设计成能够通过Internet与其它应用程序之间直 ...

  3. vue 向后台提交数据

    新建template 表单 <template> <div class="add-group content"> <table class=" ...

  4. requests不加代理

    requests里的proxies不加代理可以设置为空,就会使用本机IP proxies={}

  5. JavaScript:学习笔记(4)——This关键字

    JavaScript:学习笔记(4)——This关键字 以前这篇帖子是关于闭包的,但是我想弄明白的其实是This关键字.JavaScript的this和Java等面向对象语言中的this大不一样,bi ...

  6. empty blank

    非nil对象才能调用 empty nil: 对象是否存在empty: ”“ []blank: nil emptypresent: ! blank

  7. AppStore App申请审核加速

    容芳志大牛一直是我学习的榜样 分类: iOS开发经验技巧2014-11-12 09:40 409人阅读 评论(0) 收藏 举报 有没有遇到上线后发现很严重的bug这种情况,修复bug后提交审核又是漫长 ...

  8. loj#2269. 「SDOI2017」切树游戏

    还是loj的机子快啊... 普通的DP不难想到,设F[i][zt]为带上根玩出zt的方案数,G[i][zt]为子树中的方案数,后面是可以用FWT优化的 主要是复习了下动态DP #include< ...

  9. CodeForces - 922E Birds —— DP

    题目链接:https://vjudge.net/problem/CodeForces-922E E. Birds time limit per test 1 second memory limit p ...

  10. 大数据- 自定义Log4j日记

    1.新建一个java project,在src下新建一个lib文件夹和 rescources 文件夹,resources文件夹不能命名错误. 点击File——>project Structure ...