python爬虫——爬取星巴克商品菜单

一、首先获取星巴克地址,并分析有无反爬。

星巴克菜单网址:https://www.starbucks.com.cn/menu/
url = 'https://www.starbucks.com.cn/menu/'

response = urllib.request.urlopen(url=url)

content = response.read().decode('utf-8')

print(content)

二、写程序入口,创建请求对象,并写出请求函数:

request = creat_request()
def creat_request():
    url = 'https://www.starbucks.com.cn/menu/'

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.33'
    }
    request = urllib.request.Request(url=url,headers=headers)

    return request

三、获取网页源码,并写出获取源码函数:

content = get_content(request)
def get_content(request):
    response = urllib.request.urlopen(request)

    content = response.read().decode('utf-8')

    return content

四、创建下载函数:

down_load(content)<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值