10行python代码爬取百度热榜


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


10行python代码爬取百度热榜_第1张图片

源码:

import requests
from bs4 import BeautifulSoup

response = requests.get("http://top.baidu.com/buzz?b=1")
response.encoding = response.apparent_encoding
soup = BeautifulSoup(response.text, 'lxml')
target = soup.find_all(attrs={
     "class": "keyword"})
for each in target:
    text = each.find(attrs={
     "class": "list-title"}).text
    print(text)

运行:

10行python代码爬取百度热榜_第2张图片

10行python代码爬取百度热榜_第3张图片

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