目的:输入姓名,根据选择的字体样式和字体大小,生成一份特定的个性签名
结果呈现:屏幕显示,个性签名图片的生成
注:上了研究生之后,天天敲电脑,几乎都不怎么用笔写字,写的字越来越丑了......给自己设计个签名吧,这个至少在以后小孩成绩单上签字还是可以看得过去的~
个性签名首页:http://m.kachayv.cn/
#下面为本实例的爬虫代码,若有问题可以给我留言,或者有更好的解决方法也可以私信我~
import requests from bs4 import BeautifulSoup def get_img(url,word,fonts,sizes): headers={'user-agent':'Mozilla/5.0'} data={ 'word':word, 'fonts':fonts, 'sizes':sizes, 'fontcolor':'#ffffff', 'colors':'#FD5668' } try: r=requests.post(url,headers=headers,data=data) r.raise_for_status() r.encoding=r.apparent_encoding html=r.text soup=BeautifulSoup(html,'html.parser') div=soup.find('div',{'class':{'sctp'}}) img=div('img')[0]['src'] img_url=start_url+img r_img=requests.get(img_url) name='{}的个性签名.jpg'.format(word) with open(name,'wb')as f: f.write(r_img.content) f.close() print('{}的个性签名生成成功!'.format(word)) except Exception as e: print(e) def get_choices(url): headers={'uset-agent':'Mozilla/5.0'} try: r=requests.get(url,headers=headers) r.raise_for_status() r.encoding=r.apparent_encoding html=r.text soup=BeautifulSoup(html,'html.parser') font_value=[] font_show=[] select_fonts=soup.find('select',{'name':{'fonts'}}) for option in select_fonts('option'): font_value.append(option['value']) font_show.append(option.text.strip()) size_value=[] size_show=[] select_sizes=soup.find('select',{'name':{'sizes'}}) for option in select_sizes('option'): size_value.append(option['value']) size_show.append(option.text.strip()) return font_show,font_value,size_show,size_value except Exception as e: print(e) pass if __name__ == '__main__': word=input('请输入你的名字:').strip() start_url='http://m.kachayv.cn/' font_show, font_value, size_show, size_value=get_choices(start_url) #字体显示 font_dic={} for i in range(len(font_show)): print(font_show[i]) font_dic[i+1]=font_value[i] font_choice=int(input('请选择字体样式:').strip()) fonts=font_dic[font_choice] #大小显示 size_dic={} for i in range(len(size_show)): print('{}.{}'.format(i+1,size_show[i])) size_dic[i+1]=size_value[i] size_choice=int(input('请选择字体大小:').strip()) sizes=size_dic[size_choice] get_img(start_url,word,fonts,sizes)
结果显示:
(1)屏幕显示:
(2)文件夹显示:
嘻嘻,好可爱(*╹▽╹*)~~~~
今天是圣诞节~~~祝大家圣诞节快乐!
今日爬虫完成!
今日鸡汤:你怎么对待生活,生活就会怎么对待你。学会对自己负责,生活不能得过且过。
加油ヾ(◍°∇°◍)ノ゙