当前位置: 首页 > news >正文

python网络爬虫实例

目录

1、访问百度

2、输入单词百度翻译

3、豆瓣电影排行榜

4、豆瓣电影top250

5、下载美女壁纸


1、访问百度

from urllib.request import urlopen
url="http://www.baidu.com"
resp=urlopen(url)with open("mybaidu.html",mode="w") as f:f.write(resp.read().decode("utf-8"))
print("over!")

2、输入单词百度翻译

import requests
url="https://fanyi.baidu.com/sug"
s=input("请输入你要翻译的英文单词")
dat={"kw":s}
#发送POST请求
resp=requests.post(url,data=dat)
print(resp.json())
resp.close()

3、豆瓣电影排行榜


import requests
url="https://movie.douban.com/j/chart/top_list"
param={"type": "24",
"interval_id": "100:90",
"action":"",
"start":"0",
"limit": "20"}
header={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"}
#发送get请求
resp=requests.get(url,params=param,headers=header)
print(resp.json())
resp.close()

图片

4、豆瓣电影top250

import requests
import re
url="https://movie.douban.com/top250"
header={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"}
resp=requests.get(url,headers=header)
page_content=resp.text
obj=re.compile(r'<li>.*?<div class="item">.*?<span class="title">(?P<name>.*?)</span>.*?<p class="">.*?<br>(?P<year>.*?)&nbsp.*?<span class="rating_num" property="v:average">(?P<score>.*?)</span>.*?<span>(?P<num>.*?)人评价</span>',re.S)
result=obj.finditer(page_content)for it in result:print(it.group("name"))print(it.group("year").strip())print(it.group("score"))print(it.group("num"))
print("over!")

5、下载美女壁纸

import requests
from bs4 import BeautifulSoup
import time
url="https://www.umei.cc/bizhitupian/meinvbizhi/"
#header={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"}
resp=requests.get(url)
resp.encoding='utf-8'
main_page=BeautifulSoup(resp.text,"html.parser")
alist=main_page.find("div",class_="item_list infinite_scroll").find_all("a")
for a in alist:href="http://umei.cc"+a.get("href")child_page_resp=requests.get(href)child_page_resp.encoding='utf-8'child_page=BeautifulSoup(child_page_resp.text,"html.parser")b=child_page.find("div",class_="big-pic")img=b.find("img")src=img.get("src")img_resp=requests.get(src)img_name=src.split("/")[-1]with open(img_name,mode="wb") as f:f.write(img_resp.content)print("over!",img_name)time.sleep(1)
print("all over!")

图片

http://www.lryc.cn/news/206797.html

相关文章:

  • ArcGIS中如何为跨带数据投影?
  • 如何在Ubuntu中安装libevent库
  • 领域高口碑 | 中科院1区TOP,Elsevier出版社,仅1个月Accept!稳定检索40年!
  • RDBMS 的历史回顾
  • windows 离线安装 vue 环境
  • python实现批量pdf转txt和word
  • c++ 并发与多线程(12)线程安全的单例模式-2
  • 银河麒麟v10x86或者arm离线安装服务
  • 【Ansible自动化运维工具 1】Ansible常用模块详解(附各模块应用实例和Ansible环境安装部署)
  • Telegram 引入了国产小程序容器技术
  • Capture One Pro 23图像处理工具「Mac」
  • rust OJ实战
  • 聊聊KafkaListener的实现机制
  • Golang洗牌算法(Golang乱序算法)
  • SpringBoot 源码分析(三) 监听器分析以及属性文件加载分析
  • 记录nvm use node.js版本失败,出现报错: exit status 1: ��û���㹻��Ȩ��ִ�д˲�����
  • 【蓝牙协议】简介:蓝牙芯片、蓝牙协议架构
  • 【深度学习】
  • centos启动tomcat 并指定jdk 版本
  • day37(事件轮询机制 ajaxGet执行步骤与案例(五个步骤) ajax属性 PHP返回JSON对象(两种))
  • Flume基本使用--mysql数据输出
  • MySQL——EXPLAIN用法详解
  • 69 划分字母区间
  • 文件上传漏洞(1), 文件上传绕过原理
  • 【ARM 嵌入式 C 入门及渐进 10 -- 冒泡排序 选择排序 插入排序 快速排序 归并排序 堆排序 比较介绍】
  • 虹科 | 解决方案 | 汽车示波器 学校教学方案
  • 广播和组播(多播)
  • 【Linux】gdb调试
  • MySQL创建函数及其使用
  • 大数据-Storm流式框架(四)---storm容错机制