首页 > 编程语言 > 详细

python简单爬虫

时间:2018-06-24 10:13:40      阅读:210      评论:0      收藏:0      [点我收藏+]

      学了几天python,写了个简单的爬虫程序(爬取酷我音乐排行榜):

 

 1 #! -*- coding:utf-8 -*-
 2 
 3 import requests
 4 import pyquery
 5 from pyquery import PyQuery as pq
 6 
 7 # 爬取酷我音乐排行榜
 8 headers = {
 9     User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0}  # 设置User-Agent头,绕过反爬虫机制
10 url = "http://www.kuwo.cn/bang/index"  # 爬取的地址
11 html = requests.get(url, headers=headers)  # 获取网页内容
12 a = pq(html.text)
13 b = a(.name).find(a)
14 for c in b.items():
15     print(c.html())
16 print("爬取完成!")
17 
18 
19  

 

python简单爬虫

原文:https://www.cnblogs.com/shihun/p/9219246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!