• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python爬取虎牙直播颜值区美女主播照片

python 搞java代码 3年前 (2022-05-21) 15次浏览 已收录 0个评论

前言

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。

PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取

python免费学习资料以及群交流解答点击即可加入

基本环境配置

  • python 3.6
  • pycharm
  • requests
  • parsel

相关模块pip安装即可

确定网址

<code class="language-python">https://<a href="https://www.gaodaima.com/tag/www" title="查看更多关于www的文章" target="_blank">www</a>.huya.<a href="https://www.gaodaima.com/tag/com" title="查看更多关于com的文章" target="_blank">com</a>/g/2168
</code>

www#gaodaima.com来源gaodai#ma#com搞@代~码网搞代码

请求网页

<code class="language-python">import requests

url = "https://www.huya.com/g/2168"
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
}
response = requests.get(url=url, headers=headers)
print(repsonse.text)
</code>

解析网页数据

<code class="language-python">import parsel
selector = parsel.Selector(response.text)
urls = selector.css(".live-list .game-live-item a img::attr(data-original)").getall()
titles = selector.css(".live-list .game-live-item a img::attr(title)").getall()
info_data = zip(urls, titles)
for i in info_data:
    img_url = i[0].split("?")[0]
    title = i[1]
</code>

保存数据

<code class="language-python">    img_url_response = requests.get(url=img_url, headers=headers)
    path = "D:pythondemo虎牙img" + title + ".jpg"
    with open(path, mode="wb") as f:
        f.write(img_url_response.content)
        print(title)
</code>

实现效果


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python爬取虎牙直播颜值区美女主播照片
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址