爬汽车之家
Posted guobaoyuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬汽车之家相关的知识,希望对你有一定的参考价值。
爬汽车之家:
pip install requests pip install BeautifulSoup from bs4 import BeautifulSoup import requests ret = requests.get(‘https://www.autohome.com.cn/news/‘) # 通过requests模块获取一个对象 ret.encoding = ‘gbk‘ # 改变显示格式 # print(ret.text) #打印这个网站的字符串 soup = BeautifulSoup(ret.text,‘html.parser‘) # 通过这个BeautifulSoup把字符串变成html对象 div=soup.find(name="div",attrs={"id":"auto-channel-lazyload-article"}) #find:找到与之相匹配的第一个标签 # print(div) li_list=div.find_all(name="li") #fing_all:找到所有的 for li in li_list: # print("******************",li) title=li.find(name="h3") if not title: continue img=li.find(name="img") src=img.get("src") src="https:"+src #图片链接 #再次发起请求,下载图片 file_name=src.rsplit("/",maxsplit=1)[1] #以图片命名 img_name = ‘img_file{}‘.format(file_name) ret=requests.get(src) #再次发请求 with open(file_name,"wb") as f: f.write(ret.content) # 将图片二进制写进文件
python一行代码打印心
print(‘ ‘.join([‘‘.join([(‘PYTHON!‘[(x-y)%7]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else‘ ‘)for x in range(-30,30)])for y in range(15,-15,-1)]))
python画玫瑰花
import turtle # 设置初始位置 turtle.penup() turtle.left(90) turtle.fd(200) turtle.pendown() turtle.right(90) # 花蕊 turtle.fillcolor("red") turtle.begin_fill() turtle.circle(10, 180) turtle.circle(25, 110) turtle.left(50) turtle.circle(60, 45) turtle.circle(20, 170) turtle.right(24) turtle.fd(30) turtle.left(10) turtle.circle(30, 110) turtle.fd(20) turtle.left(40) turtle.circle(90, 70) turtle.circle(30, 150) turtle.right(30) turtle.fd(15) turtle.circle(80, 90) turtle.left(15) turtle.fd(45) turtle.right(165) turtle.fd(20) turtle.left(155) turtle.circle(150, 80) turtle.left(50) turtle.circle(150, 90) turtle.end_fill() # 花瓣1 turtle.left(150) turtle.circle(-90, 70) turtle.left(20) turtle.circle(75, 105) turtle.setheading(60) turtle.circle(80, 98) turtle.circle(-90, 40) # 花瓣2 turtle.left(180) turtle.circle(90, 40) turtle.circle(-80, 98) turtle.setheading(-83) # 叶子1 turtle.fd(30) turtle.left(90) turtle.fd(25) turtle.left(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(-80, 90) turtle.right(90) turtle.circle(-80, 90) turtle.end_fill() turtle.right(135) turtle.fd(60) turtle.left(180) turtle.fd(85) turtle.left(90) turtle.fd(80) # 叶子2 turtle.right(90) turtle.right(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(80, 90) turtle.left(90) turtle.circle(80, 90) turtle.end_fill() turtle.left(135) turtle.fd(60) turtle.left(180) turtle.fd(60) turtle.right(90) turtle.circle(200, 60)
python其他画图实例:
import turtle t = turtle.Pen() turtle.bgcolor("black") sides=6 colors=["red","yellow","green","blue","orange","purple"] for x in range(360): t.pencolor(colors[x%sides]) t.forward(x*3/sides+x) t.left(360/sides+1) t.width(x*sides/200) 准备好辣眼睛吧 import turtle t = turtle.Pen() turtle.bgcolor("black") my_name=turtle.textinput("输入你的姓名:") colors=["red","yellow","purple","blue"] for x in range(100): t.pencolor(colors[x%4]) t.penup() t.forward(x*4) t.pendown() t.write(my_name,font=("Arial",int((x+4)/4),"bold")) t.left(92)
以上是关于爬汽车之家的主要内容,如果未能解决你的问题,请参考以下文章