Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

取得固定页面内容
用Google Chrom打开需要的页面,比如
http://news.sina.com.cn/c/nd/2017-05-08/doc-ifyeycfp9368908.shtml
网页空白处右击“检查”,选“Network”, 选“Doc”,在“Response”中可以找到正文标题,比如“国土部:5月到9月实行汛期地质灾害日报告制度”
Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)

Python抓取新浪新闻数据(一)
然后选“Headers”
Python抓取新浪新闻数据(一)
确定http://news.sina.com.cn/c/nd/2018-06-06/doc-ihcqccip0158262.shtml是我们需要的网页
打开网页 http://news.sina.com.cn/c/nd/2018-06-06/doc-ihcqccip0158262.shtml
然后,选最左边的 Select an element in the page to inspect in. 然后,选Elements,再点选网页标题,可以看到Elements中的内容自动跳到了 <h1 class="main-title">这三家芯片巨头突遭反垄断调查 中国亮剑了</h1>
Python抓取新浪新闻数据(一)
Python抓取新浪新闻数据(一)
来源与时间
打开网页http://news.sina.com.cn/c/nd/2017-05-08/doc-ifyeycfp9368908.shtml
同以上例方法,点选右上角时间,在elements中找到time-source
Python抓取新浪新闻数据(一)
Python抓取新浪新闻数据(一)
接下来我们需要想办法将时间和来源分开来,这时需要使用到contents; 我们先在后面加上.contents,运行下后会看到上面的内容会在列表中分为如下2个元素
Python抓取新浪新闻数据(一)
Python抓取新浪新闻数据(一)
Python抓取新浪新闻数据(一)
Python抓取新浪新闻数据(一)
Python抓取新浪新闻数据(一)

猜你喜欢

转载自blog.51cto.com/2290153/2126860