女孩名字常用字大全: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)
此代码仅供学习与交流,请勿用于商业用途。