文章标题
来源:互联网 发布:手机淘宝评价删除不掉 编辑:程序博客网 时间:2024/06/07 08:29
Requests+BeautifulSoup实现爬虫
没有requests库的可采用pip install requests进行安装 此处所采用的python版本为Python3.5
import requestsfrom bs4 import BeautifulSoupglobal urldef getshouye(): html=requests.get("http://www.jianshu.com/") #print('html.text') content=html.text bsobj=BeautifulSoup(content,"lxml") namelist=bsobj.find_all("a",class_='blue-link') for name in namelist: print(name.text) url=name['href'] #getwriter(url) writer_html=requests.get("http://www.jianshu.com/"+url) writer_cont=writer_html.text writer_bs=BeautifulSoup(writer_cont,'lxml') writer_info=writer_bs.find_all("div",class_='meta-block') for info in writer_info: #info= if info.a is not None: flowing=info.a.p.text print("%s" %(info.a.i.previous_element)) else: print("%s: % s" % (info.div.text,info.p.text)) #passgetshouye()
”’
此处代码有有点问题,应该是会打印出关注,粉丝,文章的个数,有兴趣的小伙伴们可以对代码进行修改。当然,作为一个学了几天python的我写出的这个爬虫有很多问题,所以还是沉下心来继续学习基础知识。真的不建议大家着急,一上来就想弄这弄那的,还是要打好基础。
对于才代码中的一些问题可以自行百度,或者留言。
哈哈,搬砖去啦,大家加油。
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- python下类中函数的执行数序
- BZOJ 1579: [Usaco2009 Feb]Revamping Trails 道路升级 分层图最短路
- Hadoop学习笔记十二 YARN基础知识
- cdev wrapper for block rw
- 在项目中如何使用ja-micro框架(一)
- 文章标题
- 嵌入式Linux设备驱动开发笔记(一)
- Python基础概念_4_控制流程
- ArrayList add方法
- Open Source Research and Study with GitHub
- 凸包问题 nyoj 266 wall
- 生成二维码
- 航模电池笔记
- 234. Palindrome Linked List