Python爬虫入门

1、Python爬虫概述:
Python和爬虫:

并非只有Python能写爬虫,java,c 都能写爬虫。只是Python更方便,更简单。

合法化:

爬虫是一个工具,不被禁止。

爬虫的矛与盾:

爬与反爬

robots.TXT协议:君子协议
2、Python第一次尝试爬虫
代码:
from urllib.request import urlopen
url="http://www.baidu.com/";
resp=urlopen(url);
with open("mybaidu.html",mode="w",encoding="utf-8") as f:
    f.write(resp.read().decode("utf-8"))
print("结束");
运行结果:
<!DOCTYPE html><!--STATUS OK-->
 <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta content="always" name="referrer"><meta name="theme-color" content="#ffffff"><meta name="description" content="全球领先的中文搜索引擎、致力于让网民更便捷地获取信息,找到所求。百度超过千亿的中文网页数据库,可以瞬间找到相关的搜索结果。"><link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" /><link rel="icon" sizes="any" mask href="//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg"><link rel="dns-prefetch" href="//dss0.bdstatic.com"/><link rel="dns-prefetch" href="//dss1.bdstatic.com"/><link rel="dns-prefetch" href="//ss1.bdstatic.com"/><link rel="dns-prefetch" href="//sp0.baidu.com"/><link rel="dns-prefetch" href="//sp1.baidu.com"/><link rel="dns-prefetch" href="//sp2.baidu.com"/><title>百度一下,你就知道</title><style index="newi" type="text/css">#form .bdsug{top:39px}.bdsug{display:none;position:absolute;width:535px;background:#fff;
3、web请求分类
1 服务器渲染:

在服务器直接把数据和HTML整合在一起,同一返回给浏览器。

在页面源代码中能看到数据。

2 客户端渲染:

第一次请求只要一个HTML骨架,第二次请求拿到数据,进行数据展示。

在源代码中看不到数据。

(熟练使用浏览器抓包工具)

4、HTTP协议
协议:

两个计算机之间为了能够流畅的进行沟通而设置的一个君子协定。

常见协议:

tcp/ip,UDP,HTTP,SOAP,SMTP。

HTTP协议, Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web)服务器传输超文本到本地浏览器的传送协议.直白点儿,就是浏览器和服务器之间的数据交互遵守的就是HTTP协议.

HTTP协议把一条消息分为三大块内容.无论是请求还是响应都是三块内容。
请求:
请求行→请求方式(get/post)请求url地址协议

请求头-→放一些服务器要使用的附加信息

请求体->一般放一些请求参数
响应:
状态行->协议状态码

响应头->放一些客户端要使用的一些附加信息

响应体->服务器返回的真正客户端要用的内容CHTML,json)
请求头中最常见的一些重要内容(爬虫需要):
  1. User-Agent:请求载体的身份标识(用啥发送的请求)
  2. Referer:防盗链(这次请求是从哪个页面来的?反爬会用到
  3. cookie:本地字符串数据信息(用户登录信息,反爬的token)。
响应头中一些重要的内容:
  1. cookie:本地字符串数据信息(用户登录信息,反爬的token)
  2. 各种神奇的莫名其妙的字符串(这个需要经验了,一般都是token字样,防止各种攻击和反爬)
请求方式:

1、get:显示提交。

2、post:隐示提交。

5、requests入门:

安装requests:

1、终端运行:(比较慢)

pip install requests

2、镜像安装:pip清华源

临时使用:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
实验代码1(搜狗浏览器接口):
import requests
query=input("输入搜索内容:")

url=f'https://www.sogou.com/web?query={query}'
head={
    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Mobile Safari/537.36 Edg/101.0.1210.53"
}
resp=requests.get(url,headers=head)
print(resp)
print(resp.text)
实验代码2(百度翻译)
import requests

url="https://fanyi.baidu.com/sug"
s=input("输入翻译单词:")
dat={
    "kw":s
}
resp=requests.post(url,data=dat)
print(resp.json())
实验代码3(豆瓣电影排行)
import requests
url="https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&start=0&limit=20"
dat={
    "type": 24,
    "interval_id": "100:90",
    "action": "",
    "start": 0,
    "limit": 20
}
head={
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Mobile Safari/537.36 Edg/101.0.1210.53"
}
resp=requests.get(url,params=dat,headers=head)
print(resp.json())
6、数据解析概述

1、re解析

2、bs4解析

3、xpath解析

这三种方式可以混合进行使用,完全以结果做导向,只要能拿到你想要的数据.用什么方案并不重要。

7、基础正则表达式
前言:

Regular Expression,正则表达式

一种使用表达式的方式对字符串进行匹配的语法规则。

我们抓取到的网页源代码本质上就是一个超长的字符串,想从里面提取内容.用正则再合适不过了。

正则的优点:速度快,效率高,准确性高。

正则的缺点:新手上手难度有点儿高.。

不过只要掌握了正则编写的逻辑关系,写出一个提取页面内容的正则其实并不复杂。

正则的语法:使用元字符进行排列组合用来匹配字符串在线测试正则表达式https:/tool.oschina.netregex

常见正则表达式:

1、字符:

image-20220803150152197

2、锚点和边界:

image-20220803150321710

3、数量表示:

image-20220803150404696

4、特殊标识:

image-20220803150524648

8、Re模块
示例代码1:
import re

# findall的用法(返回一个list)
list1 = re.findall(r"\d+", "我的电话号码是:10089,他的电话号码是:66666")
print(list1)
# finditer的用法(返回一个迭代器)
it = re.finditer(r"\d+", "我的电话号码是:10089,他的电话号码是:66666")
for i in it:
    print(i)
    print(i.group())
# search的用法只查找一个就返回
s = re.search(r"\d+", "我的电话号码是:10089,他的电话号码是:66666")
print(s)
print(s.group())
# match用法,从头开始匹配
m = re.match(r"\d+", "10089,他的电话号码是:66666")
print(m.group())
print()
# 预加载正则表达式
obj = re.compile(r"\d+")
end = obj.finditer("我的电话号码是:10089,他的电话号码是:66666")
for i in end:
    print(i.group())
ne = obj.findall("还我1000")
print(ne)

运行结果:
C:\Users\lenovo\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/pythonProject2/Re1.py
['10089', '66666']
<re.Match object; span=(8, 13), match='10089'>
10089
<re.Match object; span=(22, 27), match='66666'>
66666
<re.Match object; span=(8, 13), match='10089'>
10089
10089

10089
66666
['1000']

进程已结束,退出代码0

示例代码2:
import re

s="""
    <div class='jay'><span id='1'>郭麒麟</span></div>
    <div class='jj'><span id='2'>宋铁</span></div>
    <div class='jolin'><span id='3'>大聪明</span></div>
    <div class='sylar' ><span id='4'>范思哲</span></div>
    <div class='tory' ><span id='5'>胡说八道</span></div>
  """

obj=re.compile(r"<div class='.*?'><span id='(?P<ID>\d+)'>(?P<xm>.*?)</span></div>",re.S)
m = obj.finditer(s)
for it in m:
    print(it.group("ID")+":"+it.group("xm"))


运行结果:
C:\Users\lenovo\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/pythonProject2/venv/Re2.py
1:郭麒麟
2:宋铁
3:大聪明

进程已结束,退出代码0

9、豆瓣电影top250爬取
示例代码:
import requests
import re
import csv

# 解析HTML书写正则表达式
obj = re.compile(r'<li>.*?<div class="item">.*?<span class="title">(?P<name>.*?)'
                 r'</span>.*?<p class="">.*?<br>(?P<year>.*?)&nbsp.*?<span '
                 r'class="rating_num" property="v:average">(?P<score>.*?)</span>'
                 r'.*?<span>(?P<pnum>.*?)人评价</span>',re.S) # re.S可以是.匹配所以字符包括换行
# 获取客户端agent
head={
"user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Mobile Safari/537.36 Edg/101.0.1210.53"
}
# 创建CSV文件
f = open("豆瓣电影top250.csv",mode="w",encoding='utf-8',newline='')#添加newline取出文件中多余空行
csvw = csv.writer(f)

# 循环爬取数据
q=0
while q<=250:
    # 每次循环更改URL携带参数
    par={'start':q}
    url="https://movie.douban.com/top250"
    resp = requests.get(url,headers=head,params=par)
    # 提取数据
    result = obj.finditer(resp.text)
    # 将数据写入CSV文件
    for it in result:
        dic = it.groupdict()# 创建字典
        dic['year'] = dic['year'].strip()
        csvw.writerow(dic.values())#将字典中数据写入文件
    q+=25
f.close()
print("ok!")

运行结果(csv文件):
肖申克的救赎,1994,9.7,2664689
霸王别姬,1993,9.6,1978188
阿甘正传,1994,9.5,2002172
泰坦尼克号,1997,9.4,1961608
这个杀手不太冷,1994,9.4,2148452
美丽人生,1997,9.6,1229675
千与千寻,2001,9.4,2078306
辛德勒的名单,1993,9.6,1025935
盗梦空间,2010,9.4,1916860
星际穿越,2014,9.4,1615171
忠犬八公的故事,2009,9.4,1309012
楚门的世界,1998,9.3,1536014
海上钢琴师,1998,9.3,1560701
三傻大闹宝莱坞,2009,9.2,1737160
机器人总动员,2008,9.3,1227611
放牛班的春天,2004,9.3,1211689
无间道,2002,9.3,1238506
疯狂动物城,2016,9.2,1758339
大话西游之大圣娶亲,1995,9.2,1423668
熔炉,2011,9.3,866833
控方证人,1957,9.6,478458
教父,1972,9.3,886167
当幸福来敲门,2006,9.2,1413601
触不可及,2011,9.3,997918
怦然心动,2010,9.1,1697633
龙猫,1988,9.2,1174357
末代皇帝,1987,9.3,795693
......
...
......
末路狂花,1991,8.9,217921
火星救援,2015,8.5,660767
阿飞正传,1990,8.5,468856
谍影重重,2002,8.6,393681
再次出发之纽约遇见你,2013,8.6,398473
海洋,2009,9.1,150421
朗读者,2008,8.6,430527
千年女优,2001,8.8,233744
穿越时空的少女,2006,8.6,357838
香水,2006,8.5,512200
地球上的星星,2007,8.9,191210
我爱你,2011,9.1,153736
完美陌生人,2016,8.5,493881
弱点,2009,8.7,266811
驴得水,2016,8.3,859928
浪潮,2008,8.7,258481

10、电影天堂下载链接爬取
示例代码:
import requests
import re

# 电影天堂主页
url="http://www.dytt89.com/"
# resp = requests.get(url,verify=False)# verify安全验证
resp = requests.get(url)
resp.encoding = 'gb2312'
# 主页提取数据
obj=re.compile(r"2022必看热片.*?<ul>(?P<ul>.*?)</ul>",re.S)
result = obj.search(resp.text)
s=result.group("ul")
# print(result.group("ul"))

# 提取子页中数据和下载链接
obj1=re.compile(r"<li><a href='(?P<href>.*?)' title=(?P<name>.*?)>.*?</font></span></li>",re.S)

obj2=re.compile(r'<div class="title_all"><h1>.*?《(?P<movie>.*?)》.*?</h1>.*?<td'
                r' style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(?P<download>.*?)"',re.S)
child_hlist=[]#子URLlist
ru=obj1.finditer(s)
print(ru.__sizeof__())#电影数量
for it in ru:
        print(it.group("name").strip('"'))
        childh=url+it.group("href").strip('/')
        child_hlist.append(childh)

# 获取下载链接
for url in child_hlist:
    res1=requests.get(url)
    res1.encoding='gb2312'
    # print(res1.text)
    end=obj2.search(res1.text)
    print(end.group("movie"))
    print()
    print(end.group("download"))
    print()

运行结果:
C:\Users\lenovo\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/pythonProject2/venv/电影天堂.py
32
2021年中国香港动作犯罪片《反贪风暴5:最终章》蓝光双语中字
2022年美国8.3分喜剧奇幻片《瞬息全宇宙》蓝光中英双字
2022年英国8.3分爱情片《唐顿庄园2》BD中英双字
2022年美国科幻灾难片《月球陨落》蓝光中英双字
2022年英国奇幻片《神奇动物:邓布利多之谜》BD中英双字
2021年国产6.3分动作灾难片《峰爆》蓝光国语中字
2021年韩国6.9分恐怖古装片《王国:北方的阿信》蓝光韩语中字
2022年美国7.6分动作犯罪片《新蝙蝠侠》蓝光国英双语中字
2022年美国动作科幻片《暗夜博士:莫比亚斯》BD中英双字
2022年国产喜剧爱情片《四海》HD国语中字
2022年国产7.2分历史战争片《长津湖之水门桥》HD国语中字
2022年美国6.3分动作冒险片《神秘海域》BD英语中字
2022年国产7.4分剧情片《奇迹・笨小孩》HD国语中字
2022年国产6.5分喜剧片《这个杀手不太冷静》HD国语中字
2022年国产7.7分战争历史片《狙击手》HD国语中字
反贪风暴5:最终章

magnet:?xt=urn:btih:61f0db431945e3c87820d6f8b1abdec280d405e7&dn=[电影天堂www.dytt89.com]反贪风暴5:最终章-2021_蓝光国粤双语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

瞬息全宇宙

magnet:?xt=urn:btih:6a3bff2c10457e609b68b6f09a7352aa93702982&dn=[电影天堂www.dytt89.com]瞬息全宇宙-2022_蓝光中英双字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

唐顿庄园2

magnet:?xt=urn:btih:a9889764eff1074bb910e7bab54c1bb94970b570&dn=[电影天堂www.dytt89.com]唐顿庄园2-2022_BD中英双字V3.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

月球陨落

magnet:?xt=urn:btih:518dc502d8614c04144019f039c63b608aced839&dn=[电影天堂www.dytt89.com]月球陨落-2022_蓝光中英双字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

神奇动物:邓布利多之谜

magnet:?xt=urn:btih:a1256c3e78e816997388be0e60835b8b8a0de679&dn=[电影天堂www.dytt89.com]神奇动物:邓布利多之谜-2022_BD中英双字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

峰爆

magnet:?xt=urn:btih:69053cdbee29af479dfc6919306fecc37ff9f377&dn=[电影天堂www.dytt89.com]峰爆-2021_蓝光国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

王国:北方的阿信

magnet:?xt=urn:btih:34b93ccbdd8e86efc0e10887d0bb7be1e722a9b1&dn=[电影天堂www.dytt89.com]王国:北方的阿信-2021_蓝光韩语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

新蝙蝠侠

magnet:?xt=urn:btih:cc3d0273424690b8eb20bc1516c35b472697b010&dn=[电影天堂www.dytt89.com]新蝙蝠侠-2022_蓝光国英双语中字V3.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

暗夜博士:莫比亚斯

magnet:?xt=urn:btih:46b81d975dee04cc81e65a9755a4b07225286eec&dn=[电影天堂www.dytt89.com]暗夜博士:莫比亚斯-2022_BD中英双字V2.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

四海

magnet:?xt=urn:btih:d4d5a1a0b378147a520429f6af88f5280b4be20a&dn=[电影天堂www.dytt89.com]四海-2022_HD国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

长津湖之水门桥

magnet:?xt=urn:btih:029cd88f780e4482750abcdb448993cb0431adb5&dn=[电影天堂www.dytt89.com]长津湖之水门桥-2022_HD国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

神秘海域

magnet:?xt=urn:btih:6fe981cf144093b246fa3ecdb3e672834187aeb1&dn=[电影天堂www.dytt89.com]神秘海域-2022_BD英语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

奇迹・笨小孩

magnet:?xt=urn:btih:5113ba28bb2e6264e9766fdd1d04a5acab4168f2&dn=[电影天堂www.dytt89.com]奇迹・笨小孩-2022_HD国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

这个杀手不太冷静

magnet:?xt=urn:btih:1463cee8534c6ba7b144e05fa96e5ab71b6f5b2a&dn=[电影天堂www.dytt89.com]这个杀手不太冷静-2022_HD国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce

狙击手

magnet:?xt=urn:btih:a01f9994f1ac1fb291f81c087303f401ff3e3549&dn=[电影天堂www.dytt89.com]狙击手-2022_HD国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce


进程已结束,退出代码0

11、bs4用法

安装(终端输入):

pip install bs4

镜像安装也行:网上搜索。

示例代码(北京新发地市场价格):
from bs4 import BeautifulSoup
import requests

url = "http://www.xinfadi.com.cn/getPriceData.html"
head={
"User-Agent" : "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Mobile Safari/537.36 Edg/101.0.1210.53"
}
resp = requests.get(url,headers=head)
print(resp.text)

# 获取HTML页面交给BeautifulSoup处理,生成bs对象
page = BeautifulSoup(resp.text,'html.parser')#'html.parser'指定其为HTML
# 查找数据
# 1 find(第一个)
# 2 find_all(全部)

# table = page.find("id",class_="???")
table = page.find("id",attrs={"class":"???"})
print(table)
trs = table.find_all("tr")[1:]#查找第二项到最后一项
for tr in trs:
    tds=tr.find_all_next("td")
    name = tds[0].text
    low = tds[1].text
    #.......

12、优美图库爬取下载:
示例代码:
import requests
from bs4 import BeautifulSoup

# 获取到主页HTML
url = "https://www.umei.cc/bizhitupian/weimeibizhi/"
resp=requests.get(url)
resp.encoding='utf-8'
# print(resp.text)

# 使用bs4解析获取子页href
main_page=BeautifulSoup(resp.text,'html.parser')
newmain = main_page.find('div',class_="swiper-wrapper after").find_all('a')
print(newmain.__sizeof__())
for hre in newmain:
    href="https://www.umei.cc/"+hre.get("href").strip('/')
    # print(href)

    # 利用href打开子页获取到图片的src下载地址
    childresp = requests.get(href)
    childresp.encoding='utf-8'
    # print(childresp.text)
    cpage = BeautifulSoup(childresp.text,'html.parser')
    imgf=cpage.find('section',class_="img-content").find('img')
    print(imgf.get('src'))

    # 下载图片
    img=imgf.get('src')
    imgresp = requests.get(img)
    urc=r"C:\\Users\\lenovo\\Desktop\\新的图片\\" #使用\\防止“\+字母”造成歧义
    imgname =urc+ img.split('/')[-1]
    with open(imgname,mode='wb') as f: #创建新的文件,写入图片
        f.write(imgresp.content)
    print("over!!!",imgname)
print("全部完成")

运行结果:
C:\Users\lenovo\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/pythonProject2/venv/优美图库.py
312
https://www.umei.cc/bizhitupian/weimeibizhi/245899.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/9e5827678bd12db0999a573254e40d1e.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\9e5827678bd12db0999a573254e40d1e.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225260.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/6b72c57a1423c866d2b9dc10d0473f27.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\6b72c57a1423c866d2b9dc10d0473f27.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245885.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/dcc60948244f0d7f6adc7c3ff4da87eb.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\dcc60948244f0d7f6adc7c3ff4da87eb.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245893.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/ba34fff6a58897cc5362b79e477c06d8.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\ba34fff6a58897cc5362b79e477c06d8.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225259.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/774218be86d832f359637ab120eba52d.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\774218be86d832f359637ab120eba52d.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245898.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/718c092b7239a6c185c2a0fc3167bef8.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\718c092b7239a6c185c2a0fc3167bef8.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225256.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/191468637cab2f0206f7d1d9b175ac81.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\191468637cab2f0206f7d1d9b175ac81.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245894.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/7fe975add2196501191db41a6dddfe21.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\7fe975add2196501191db41a6dddfe21.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/28132.htm
http://i1.shaodiyejin.com/uploads/tu/201702/180/1.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\1.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225255.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/d7de3f9faf1e0ecdea27b73139fc8d3a.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\d7de3f9faf1e0ecdea27b73139fc8d3a.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225258.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/563337d07af599a9ea64e620729f367e.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\563337d07af599a9ea64e620729f367e.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245887.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/33f06e321d65146414aefd830013dfe7.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\33f06e321d65146414aefd830013dfe7.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225254.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/3ed27e5aedc2673755bf3327e9dcc13b.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\3ed27e5aedc2673755bf3327e9dcc13b.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245886.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/587b971f4f4a2f34ec485c11120d9721.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\587b971f4f4a2f34ec485c11120d9721.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/7994.htm
http://i1.shaodiyejin.com/uploads/tu/201608/6/y4zhxrsxyof.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\y4zhxrsxyof.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225257.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/a2c58d6d726fb7ef29390becac5d8643.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\a2c58d6d726fb7ef29390becac5d8643.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245897.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/26291c282da777b06d9ca389cad82d7f.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\26291c282da777b06d9ca389cad82d7f.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/9360.htm
http://i1.shaodiyejin.com/uploads/tu/201608/18/08081491.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\08081491.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225251.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/e9d17d27dfd693d88b232899538144e8.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\e9d17d27dfd693d88b232899538144e8.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/9317.htm
http://i1.shaodiyejin.com/uploads/tu/201608/18/08081285.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\08081285.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/225253.htm
http://kr.shanghai-jiuxin.com/file/2020/1031/26b7e178e987be6d914bf8d1af120890.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\26b7e178e987be6d914bf8d1af120890.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/28133.htm
http://i1.shaodiyejin.com/uploads/tu/201702/182/1.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\1.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/28129.htm
http://i1.shaodiyejin.com/uploads/tu/201702/172/1.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\1.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/28097.htm
http://i1.shaodiyejin.com/uploads/tu/201702/166/1.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\1.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/9316.htm
http://i1.shaodiyejin.com/uploads/tu/201608/18/08081390.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\08081390.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/28059.htm
http://i1.shaodiyejin.com/uploads/tu/201702/86/1.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\1.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/9314.htm
http://i1.shaodiyejin.com/uploads/tu/201608/18/08081195.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\08081195.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/245895.htm
http://kr.shanghai-jiuxin.com/file/2022/0414/e5d9c2e8a189059e61f6f757aedb79e4.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\e5d9c2e8a189059e61f6f757aedb79e4.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/21891.htm
http://i1.shaodiyejin.com/uploads/tu/201611/232/t0onrm502lc.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\t0onrm502lc.jpg
https://www.umei.cc/bizhitupian/weimeibizhi/9365.htm
http://i1.shaodiyejin.com/uploads/tu/201608/18/08081632.jpg
over!!! C:\\Users\\lenovo\\Desktop\\新的图片\\08081632.jpg
全部完成

进程已结束,退出代码0

图片文件:

image-20220804181752390

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Python爬虫入门可以从学习使用Scrapy框架开始。Scrapy是一个用于爬取和提取结构化数据的Python应用框架。它可以帮助你快速开发和部署爬虫程序,并提供了许多方便的功能和工具来处理网页和数据。 以下是学习Python爬虫的一些建议和步骤: 1. 首先,确保你已经安装了Python和Scrapy。你可以在Python官方网站上找到安装指南,并使用pip命令安装Scrapy。 2. 了解基本的HTML和CSS知识。这将帮助你理解网页的结构和布局,以及在爬取过程中如何定位和提取数据。 3. 学习XPath或CSS选择器。这些是用于在网页中定位特定元素和数据的强大工具。你可以使用它们来选择和提取你感兴趣的数据。 4. 开始编写你的第一个爬虫程序。你可以使用Scrapy提供的命令行工具来生成一个基本的爬虫模板,然后根据你的需求进行修改和扩展。 5. 学习如何发送HTTP请求和处理响应。Scrapy提供了方便的方法和类来处理网络请求和响应,并且支持异步和并发操作。 6. 学习如何处理网页和数据。在爬虫过程中,你可能需要处理网页的链接、表单、JavaScript等。Scrapy提供了一些有用的工具和方法来处理这些问题。 7. 学习如何存储和处理爬取的数据。你可以将数据保存在文件或数据库中,或者进行进一步的处理和分析。 8. 不断实践和练习。通过爬取不同的网站和处理各种类型的数据,你可以进一步提升你的爬虫技能和经验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱打辅助的小可爱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值