python bs4爬取腾讯新闻简单练习版

import requests
from bs4 import BeautifulSoup
import pandas

res = requests.get("http://news.qq.com/")
soup = BeautifulSoup(res.text, 'html.parser')
newsary = []
for news in soup.select('.Q-tpWrap .text'):
    newsary.append({"title":news.select('a')[0].text,"url":news.select('a')[0]['href']})

newsdf = pandas.DataFrame(newsary)
newsdf.to_excel("news.xlsx")

你可能感兴趣的:(爬虫)