Greennova 发表于 2022-12-24 10:57

python爬取精美壁纸

import requestsfrom lxml import etree
import time
url = "https://desk.3gbizhi.com/deskDM/"
headers1 = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
    }
response = requests.get(url=url,headers=headers1)
#print(response.text)
tree = etree.HTML(response.text)
list = tree.xpath("/html/body/div/ul/li/a/@href")

for i in list:
    print(i)
    response1 = requests.get(i)
    tree1 = etree.HTML(response1.text)
    id = tree1.xpath("/html/body/div/h2/text()")
    url_source = tree1.xpath("/html/body/div/div/a/@href")#/html/body/div/div/a
    #print(id,url_source)
    url1 = url_source
    #print(url1)
    img_source = requests.get(url1)
    #下载

    with open('img//' + '3G_dongman_wp//' + id + '.jpg', mode="wb") as f:
      f.write(img_source.content)
    print("oveer!")
    time.sleep(0.1)
response1.close()
response.close()

feiyu361 发表于 2022-12-24 15:30

谢谢这些妹子,让我又来了一发

yuwen998 发表于 2023-1-4 20:00

爬取精美壁纸.py
Traceback (most recent call last):
File "C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python爬取精美壁纸.py", line 1, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

不懂,请老师解疑

bingbingbd 发表于 2022-12-24 15:45

水平用到机智了

wakin1421 发表于 2022-12-24 16:20

无脑复制运行一下,有warning

大大泡泡糖121 发表于 2022-12-24 17:19

感谢分享!

YFxbxb888 发表于 2022-12-24 17:33

feiyu361 发表于 2022-12-24 15:30
谢谢这些妹子,让我又来了一发

老哥,论坛里没有你认识的人了吗

13613105079 发表于 2022-12-24 18:11

感谢分享

虞美人草 发表于 2022-12-24 20:15



不错,好像就是一个列表的:lol

linswin 发表于 2022-12-25 09:37

一看代码里面写的xpath的路径就知道帖主是一个严谨的爬虫入门者。哈哈

constwm 发表于 2022-12-25 10:00

喔哦,喔哦,技术不就来了啊
页: [1] 2 3
查看完整版本: python爬取精美壁纸