Python爬虫百度新闻
微笑的小小刀:
有梦想,爱技术。在城市中奋斗却向往着田园生活
有故事,有酒,来来来, 与尔同销万古愁
谢谢大家支持
总体步骤
python 环境准备
页面url分析
代码抓取
python 环境准备
pycharm
beautifulSoup
requests
页面url 分析
1487561491324.png
这是直接在页面上进行百度新闻搜索,要注意url 。
这里先在python中写一段测试代码:
url = "http://news.baidu.com/ns?word=%CE%A2%D0%A6%B5%C4%D0%A1%D0%A1%B5%B6&cl=2&rn=20"
r = requests.get(url)
html = r.text
soup = BeautifulSoup(html, 'html.parser')
div_items = soup.find_all('div', class_='tn-bxitem')
在div_items那行打个断点。运行到那里之后的效果: