![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python爬虫
u011159607
这个作者很懒,什么都没留下…
展开
-
Python爬虫,如果有空格的话要增加.*?class而不是直接后面跟class
目标网站:http://bohaishibei.com/post/category/main/(一个很有趣的网站,一段话配一个图,老有意思了~)网站形式如下:爬取标题和图片链接import reimport requestsurl="https://bh.sb/post/category/main/"r=requests.get(url)print (r...转载 2019-05-08 16:38:04 · 591 阅读 · 0 评论 -
python爬虫
Python3.6请求网站时报错:http.client.RemoteDisconnected: Remote end closed connection without response调整前的代码段: data = urllib.request.urlopen(url).read()运行时报错:http.client.RemoteDisconnected: Re...转载 2019-05-06 14:52:24 · 133 阅读 · 0 评论 -
python爬虫,个人博客
#coding:utf-8import reimport urllib.requesturl = "http://www.eastmountyxz.com/"content = urllib.request.urlopen(url).read().decode('utf-8') #要加decode和.request#爬取标题title = re.findall(r'<t...转载 2019-05-06 16:46:32 · 168 阅读 · 0 评论 -
PyCharm安装第三方模块Request
File->Settings->Project Interpreter ,点击+,搜索“request”,安装成功后注意:安装成功后,我重新创建了项目,选择existing interpreter才成功的原创 2019-05-07 14:06:27 · 697 阅读 · 0 评论 -
Error: cannot use a string pattern on a bytes-like
https://blog.csdn.net/J__Max/article/details/82937774解决方法是:把’html’类型调整一下:html.decode(‘utf-8’)、from urllib import request as rrimport reurl = 'http://www.baidu.com'content = rr.urlopen(ur...转载 2019-05-07 15:33:17 · 786 阅读 · 0 评论 -
字典写入文件中
#声明一个字典dict1={"a":1,"b":99}print(type(dict1))#将字典转入为字符串,写入文件中import jsonstr=json.dumps(dict1)print(type(str))file1=open("b.txt",'w')file1.write(str) ...转载 2019-06-26 21:11:34 · 2017 阅读 · 0 评论 -
global关键字 (如果需要在函数中修改全部变量,需要使用global 来声明全局变量)
# 全局变量#global关键字(内部作用域想要对外部作用域的变量进行修改)a=100def testA(): global a #想要对全局变量进行修改,要用到关键词global a=300 print(a)testA() #结果a=300print(a) #结果300...转载 2019-06-26 22:22:17 · 6724 阅读 · 1 评论 -
json字典
dict1={"neme":3,"age":4}print(dict1)print(type(dict1))#将字典转化为字符串,使用str()import jsonstr1=str(dict1)print(str1)print(type(str1))#新建一个文档b,写入f=open("b.txt","w")f.write(str1)#字典写入之后读取出来f=op...原创 2019-06-23 23:32:56 · 1222 阅读 · 0 评论