爬取爱奇艺热搜

#爱奇艺网址:http://v.iqiyi.com/index/resou/index.html

import requests
from bs4 import BeautifulSoup
import pandas as pd
url='http://v.iqiyi.com/index/resou/index.html'#搜索网址
headers={'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'}#伪装爬虫
r=requests.get(url)#发送get请求
r.encoding=r.apparent_encoding#统一编码
soup=BeautifulSoup(r.text,'lxml')#SOUP对象
a=[]#建立表格
b=[]
for y in soup.find_all(class_="title-box-1"):
a.append(y.get_text().strip())
for x in soup.find_all(class_="title-box-3"):
b.append(x.get_text().strip())
data=[title,index]
print(data)
c=pd.DataFrame(data,index=["标题","热度"])#可视化
print(c.T)

获取标题 热度

得出的结果

猜你喜欢

转载自www.cnblogs.com/cwddbky/p/12526989.html