实战项目之-scrapy框架实现给孩子取个好名字~

女孩名字常用字大全:http://xh.5156edu.com/xm/nu.html
姓名测试打分:https://www.threetong.com/ceming/baziceming

利用上面两个网站来实现获取一个打分高的女孩名字~

spider页面:

(由于操作不难,就不写其他页的内容了)

# -*- coding: utf-8 -*-
import scrapy

class QimingSpider(scrapy.Spider):
    name = 'qiming'
    allowed_domains = ['5156edu.com','threetong.com']
    start_urls = ['http://xh.5156edu.com/xm/nu.html']

    def parse(self, response):
        #将所有字取回来,放在列表
        f_name_lis = response.xpath('//a[@class="fontbox"]/text()').extract()
        first = '程'
        name_lis = []
        #获取双字
        for a in f_name_lis:
            for b in f_name_lis:
                name =  a + b
                name_lis.append(name)
        #获取单个字
        for c in f_name_lis:
            name_lis.append(c)
        #将列表里存在的数据都遍历出来提交.
        for name in name_lis:
            Form_data = {
                "isbz":"1",
                "txtName":first,
                "name":name,
                "rdoSex":"1",
                "data_type":"0",
                "cboYear":"2019",
                "cboMonth":"4",
                "cboDay":"22",
                "cboHour":"12-午时",
                "cboMinute":"41分",
                "pid":"北京",
                "cid":"北京",
                "zty":"0",
            }
            #打分网站接口
            url = 'https://www.threetong.com/ceming/baziceming/xingmingceshi.php'
            #发送请求
            req = scrapy.FormRequest(url=url, callback=self.parse_test, formdata=Form_data)
            #将名字一同带过去
            req.meta['name'] = name

            yield req
    #接收所有返回来的名字打分页面
    def parse_test(self,response):
        #匹配相应的标签块,获取打分内容
        ls_score = response.xpath('//span[@class="df_1 left"]/text()').extract_first().lstrip('姓名理数评分:')
        bz_score = response.xpath('//span[@class="df_1 right"]/text()').extract_first().lstrip('姓名配合八字评分:')
        #如果两项打分都超过80,再输出来.
        if float(ls_score)>= 80 and float(bz_score)>= 80:
            print(response.meta['name'],ls_score,bz_score)

        # with open('qiming.html','wb')as f:
        #     f.write(response.body)

此代码仅供学习与交流,请勿用于商业用途。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值