美文网首页
2.Python 爬虫 happy一下

2.Python 爬虫 happy一下

作者: Bllose | 来源:发表于2019-07-07 11:39 被阅读0次

看图说话。附带源码。 

感兴趣的可以拷过去,然后修改“print(alt +" : " + url)”, 想干什么干什么。。(●>∀<●)

程序截图

import urllib.request# 用于发送http请求,获取网页信息

from bs4import BeautifulSoup# 用于解析网页

import time# 用于控制访问速度

# 1、获取网页,分析想获取的数据规则

# 2、通过如上规则,使用BeautifulSoup批量获取

# 3、通过如上规则,遍历整个网站的每一个页面

urlPreFix ="https://www.sex.com/"

targetUrl = urlPreFix

# 用于提取资源目标url

def geturls(target):

target = BeautifulSoup(target, 'html.parser')

for imgin target.find_all('img', src='/images/t.png'):

alt = img.attrs['alt']

url = img.attrs['data-src']

print(alt +" : " + url)

counter =1

while counter <57:

print('当前执行URL:' + targetUrl)

html = urllib.request.urlopen(targetUrl)

geturls(html)

counter +=1

    targetUrl = urlPreFix +"/?page=" +str(counter)

print('休眠5秒...')

time.sleep(5)

相关文章

网友评论

      本文标题:2.Python 爬虫 happy一下

      本文链接:https://www.haomeiwen.com/subject/lkrbhctx.html