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

Posted ashton

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Python爬校花网,刚学习爬虫的同学可以看看相关的知识,希望对你有一定的参考价值。

技术分享图片
#!/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(rsrc=",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爬校花网,刚学习爬虫的同学可以看看的主要内容,如果未能解决你的问题,请参考以下文章

爬虫网页解析之css用法及实战爬取中国校花网

Scrapy爬虫实例——校花网

教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神

转载教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神

Scrapy爬取照片

最网最全python框架--scrapy(体系学习,爬取全站校花图片),学完显著提高爬虫能力(附源代码),突破各种反爬