使用python获取百度最新国际新闻
/
import requests##网页需要调用requests
from bs4 import BeautifulSoup##去除网页标签需要用到bs4的BeautifulSoup工具
res=requests.get('http://news.baidu.com/guoji')
res.encoding='utf-8'
soup=BeautifulSoup(res.text,'html.parser')
for news in soup.select('.ulist'): ##循环soup中带有ulist类的内容
for i in range(0,len(news.select('li')),1):##循环ulist中所有的li,从0开始,最大值为li的个数,步进1,作为索引值带入后面获取标题
ha=news.select('a')[0]['href']##取出每...
阅读全文 →