欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

爬取新浪网新闻标题日期网址.py

程序员文章站 2022-05-02 22:02:17
...
import requests
from bs4 import BeautifulSoup
url ='http://news.sina.com.cn/china/'
res = requests.get(url)
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text,'html.parser')
for news in soup.select('.img-news-item'):
    time=news.select('.time')[0].text
    h2=news.select('h2')[0].text
    a=news.select('a')[0]['href']
    print(time)
    print(h2)
    print(a)
相关标签: python3