利用python爬取页面

扫描二维码关注公众号,回复: 2355126 查看本文章

目标网址:https://item.jd.com/7479820.html

  1 import requests
  2 url="https://item.jd.com/7479820.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("fail...")
代码如上,运行成功,结果如下:
[root@zsx0728 test]# python2 pythonjd.py 
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <!-- shouji -->
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <title>【华为荣耀9i】荣耀9i 4GB+64GB 魅海蓝 移动联通电信4G全面屏手机 双卡双待【行情 报价 价格 评测】-京东</title>
    <meta name="keywords" content="HUAWEI荣耀9i,华为荣耀9i,华为荣耀9i报价,HUAWEI荣耀9i报价"/>
    <meta name="description" content="【华为荣耀9i】京东JD.COM提供华为荣耀9i正品行货,并包括HUAWEI荣耀9i网购指南,以及华为荣耀9i图片、荣耀9i参数、荣耀9i评论、荣耀9i心得、荣耀9i技巧等信息,网购华为荣耀9i上京东,放心又轻松" />
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="mobile-agent" content="format=xhtml; url=//item.m.jd.com/product/7479820.html">
    <meta http-equiv="mobile-agent" content="format=html5; url=//item.m.jd.com/product/7479820.html">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <link rel="canonical" href="//item.jd.com/7479820.html"/>
        <link rel="dns-prefetch" href="//misc.360buyimg.com"/>
    <link rel="dns-prefetch" href="//static.360buyimg.com"/>
    <link rel="dns-prefetch" href="//img10.360buyimg
是的,我是颖宝的粉丝……










猜你喜欢

转载自blog.csdn.net/zsx0728/article/details/80968307
今日推荐