python爬虫代码示例:爬取京东详情页图片

一、Requests安装及示例

爬虫爬取网页内容首先要获取网页的内容,通过requests库进行获取。

  • GitHub: https://github.com/requests/requests

  • PyPl: https://pypi.python.org/pypi/requests

  • 官方文档:http://wwwpython-requests.org

  • 中文文档:http://docs.python-requests.org/zh CN/latest

安装

pip install requests

示例代码

import requests``   ``url  = "http://store.weigou365.cn"``res = requests.get(url)``res.text

执行效果如下:

二、Selenium库

爬虫爬取网页有时需要模拟网页行为,比如京东、淘宝详情页面,图片加载随着滚动自动加载的。这种情况我们就要进行浏览器模拟操作才能获取要爬取的数据。

Selenium 是一个用于自动化浏览器操作的开源框架,主要用于网页测试,支持多种浏览器包括 Chrome、Firefox、Safari 等。它提供了一系列的API,允许你模拟用户在浏览器中的行为,例如点击按钮、填写表单、导航等。

官方网站: https://sites.google.com/a/chromium.org/chromedriver``114之前版本:http://chromedriver.storage.googleapis.com/index.html``116版本:https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/win64/chromedriver-win64.zip``117之后的版本:https://googlechromelabs.github.io/chrome-for-testing/

安装

pip install selenium

示例代码

`from selenium import webdriver``browser = webdriver.Chrome()``browser.get("https://baidu.com/")``print(browser.title)``browser.quit()` 

、爬取京东详情页面代码****

`from selenium import webdriver``from lxml import etree``import time``import openpyxl``import re``import os``import reque
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值