python简易爬虫

python简易爬虫,第1张

简易的爬虫

话不多说直接上代码

 ​​​​​​

import requests
from bs4 import BeautifulSoup

m = requests.get('https://www.bilibili.com/v/popular/rank/movie')
t = requests.get('https://www.bilibili.com/v/popular/rank/tv')
html1 = m.content
html2 = t.content
movie = BeautifulSoup(html1, 'html.parser')
tv = BeautifulSoup(html2, 'html.parser')
div_list1 = movie.find('ul', attrs={'class': 'rank-list'})
div_list2 = tv.find('ul', attrs={'class': 'rank-list'})
arf1 = div_list1.find_all('a', attrs={'class': 'title'})
arf2 = div_list2.find_all('a', attrs={'class': 'title'})

for x1 in arf1:
    url1 = x1['href']
    name = x1.get_text()
    print(name+'\t点击观看链接:'+f'http:{url1}')

for x2 in arf2:
    url2 = x2['href']
    name2 = x2.get_text()
    print(name2+'\t点击观看链接:'+f'http:{url2}')

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/869429.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存