10行python代码爬取百度热榜


百度热搜榜python爬虫,仅供学习交流


在这里插入图片描述

源码:

 1 import requests
 2 from bs4 import BeautifulSoup
 3 
 4 response = requests.get("http://top.baidu.com/buzz?b=1")
 5 response.encoding = response.apparent_encoding
 6 soup = BeautifulSoup(response.text, 'lxml')
 7 target = soup.find_all(attrs={"class": "keyword"})
 8 for each in target:
 9     text = each.find(attrs={"class": "list-title"}).text
10     print(text)

 

运行:

在这里插入图片描述

在这里插入图片描述

posted @ 2021-02-21 18:32  BugMiaowu2021  阅读(186)  评论(0编辑  收藏  举报