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)