码迷,mamicode.com
首页 > 编程语言 > 详细

使用Python爬校花网,刚学习爬虫的同学可以看看

时间:2018-08-10 19:35:07      阅读:494      评论:0      收藏:0      [点我收藏+]

标签:src   tin   img   pytho   open   image   mozilla   www   hide   

技术分享图片
#!/usr/bin/evn python3
import requests
import re

class crawler(object):
    #发起请求
    def request(self,page):
        headers = {
        ‘Host‘: ‘www.xiaohuar.com‘,
        ‘Cookie‘:‘__51cke__ =;Hm_lvt_0dfa94cc970f5368ddbe743609970944 = 1533890508;bdshare_firstime = 1533890520508;Hm_lpvt_0dfa94cc970f5368ddbe743609970944 = 1533891345;__tins__17172513 = % 7B % 22sid % 22 % 3A % 201533890507945 % 2C % 20 % 22vd % 22 % 3A % 208 % 2C % 20 % 22expires % 22 % 3A % 201533893209290 % 7 D;__51laig__ = 8‘,
        ‘user-agent‘:‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36‘
        }
        html = requests.get(‘http://www.xiaohuar.com/list-1-%d.html‘ %page,headers=headers)
        print("正在爬.........")
        print(html.url)
        now = re.sub(r‘src="‘,‘src="http://www.xiaohuar.com‘,html.text)
        return now
    # 正则匹配
    def getImages(self,html):
        img = re.compile(r‘(<img.+?src=".+?" />)‘);
        url = re.findall(img, html)
        return  url
crawler = crawler()
html = crawler.request(1)
# print(html)
a = crawler.getImages(html)
for i in a:
    print(i)
View Code

技术分享图片

技术分享图片

技术分享图片

技术分享图片

需要pip install requests

使用Python爬校花网,刚学习爬虫的同学可以看看

标签:src   tin   img   pytho   open   image   mozilla   www   hide   

原文地址:https://www.cnblogs.com/ashton/p/9456583.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!