requests实例1:京东商品页面的爬取

京东某商品的页面爬取:

全代码如下(使用通用框架进行爬取):

1 import requests
2 url = "https://item.jd.com/2967929.html"
3 try:
4     r = requests.get(url)
5     r.raise_for_status()
6     r.encoding = r.apparent_encoding
7     print(r.text[:1000])
8 except:
9     print("爬取失败")

输出:

 1 <!DOCTYPE HTML>
 2 <html lang="zh-CN">
 3 <head>
 4     <!-- shouji -->
 5     <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
 6     <title>【华为荣耀8】荣耀8 4GB+64GB 全网通4G手机 魅海蓝【行情 报价 价格 评测】-京东</title>
 7     <meta name="keywords" content="HUAWEI荣耀8,华为荣耀8,华为荣耀8报价,HUAWEI荣耀8报价"/>
 8     <meta name="description" content="【华为荣耀8】京东JD.COM提供华为荣耀8正品行货,并包括HUAWEI荣耀8网购指南,以及华为荣耀8图片、荣耀8参数、荣耀8评论、荣耀8心得、荣耀8技巧等信息,网购华为荣耀8上京东,放心又轻松" />
 9     <meta name="format-detection" content="telephone=no">
10     <meta http-equiv="mobile-agent" content="format=xhtml; url=//item.m.jd.com/product/2967929.html">
11     <meta http-equiv="mobile-agent" content="format=html5; url=//item.m.jd.com/product/2967929.html">
12     <meta http-equiv="X-UA-Compatible" content="IE=Edge">
13     <link rel="canonical" href="//item.jd.com/2967929.html"/>
14         <link rel="dns-prefetch" href="//misc.360buyimg.com"/>
15     <link rel="dns-prefetch" href="//static.360buyimg.com"/>
16     <link rel="dns-prefetch" href="//img10.360buyimg.com"/>
17     <link rel="dns

转载于:https://www.cnblogs.com/Shiko/p/10827686.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值