当前位置:Gxlcms > Python > 基于Python3.4实现简单抓取爬虫功能详细介绍

基于Python3.4实现简单抓取爬虫功能详细介绍

时间:2021-07-01 10:21:17 帮助过:47人阅读

这篇文章主要介绍了Python3.4编程实现简单抓取爬虫功能,涉及Python3.4网页抓取及正则解析相关操作技巧,需要的朋友可以参考下

本文实例讲述了Python3.4编程实现简单抓取爬虫功能。分享给大家供大家参考,具体如下:


  1. import urllib.request
  2. import urllib.parse
  3. import re
  4. import urllib.request,urllib.parse,http.cookiejar
  5. import time
  6. def getHtml(url):
  7. cj=http.cookiejar.CookieJar()
  8. opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
  9. opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'),('Cookie','4564564564564564565646540')]
  10. urllib.request.install_opener(opener)
  11. page = urllib.request.urlopen(url)
  12. html = page.read()
  13. return html
  14. #print ( html)
  15. #html = getHtml("http://weibo.com/")
  16. def getimg(html):
  17. html = html.decode('utf-8')
  18. reg='"screen_name":"(.*?)"'
  19. imgre = re.compile(reg)
  20. src=re.findall(imgre,html)
  21. return src
  22. #print ("",getimg(html))
  23. uid=['2808675432','3888405676','2628551531','2808587400']
  24. for a in list(uid):
  25. print (getimg(getHtml("http://weibo.com/"+a)))
  26. time.sleep(1)

以上就是基于Python3.4实现简单抓取爬虫功能详细介绍的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行