阅读背景:

python bs4爬取腾讯新闻简单练习版_wwxy1995的博客

来源:互联网 
import requests
from bs4 import BeautifulSoup
import pandas

res = requests.get("https://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")import requests
from bs4 import BeautifulSoup
i



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: