时间:2023-07-23 13:12:01 | 来源:网站运营
时间:2023-07-23 13:12:01 来源:网站运营
Python制作表情包的学习网站收集:(41条消息) Python | 自动生成表情包,从此斗图无敌手!_杭州小胖的博客-CSDN博客import randomimport timefrom bs4 import BeautifulSoupimport requestsimport lxml.etreeimport ospage_n = int(input('请输入你需要爬取的网页数量'))for i in range(page_n): url_bqb =f'https://www.fabiaoqing.com/bqb/lists/type/hot/page/{i}.html' response = requests.get(url_bqb) html_parser = lxml.etree.HTMLParser() html = lxml.etree.fromstring(response.text,parser = html_parser) #将返回的字符串类型返回html进行解析 bqb_title = html.xpath("//div[@class ='bqppdiv']/p/text()") bqb_pic = html.xpath("//div[@class ='bqppdiv']/img/@data-original") print(bqb_pic) print(bqb_title)if not os.path.exists('bqb_pic'): os.mkdir('bqb_pic')for title,pic in zip(bqb_title,bqb_pic): title = title.replace("/","-").replace(":","").replace("?","") pic_stream = requests.get(pic,stream=True) with open(os.path.join('bqb_pic',title + '.jpg'),'wb+') as writer: writer.write(pic_stream.raw.read()) print(f'info{title}.jpg下载成功') time.sleep(random.uniform(0.1,0.4))
关键词:学习,收集,表情