diff --git a/搜索博主.py b/搜索博主.py new file mode 100644 index 0000000..49197ed --- /dev/null +++ b/搜索博主.py @@ -0,0 +1,39 @@ +import requests +from lxml import etree +from selenium import webdriver +import time +from bs4 import BeautifulSoup +import re +# 480959917 +# 1856528671 +# https://space.bilibili.com/480959917/video +# https://space.bilibili.com/480959917/video?tid=0&page=2&keyword=&order=pubdate +uid=input('请输入你想要看的博主的uid:') +base_url='https://space.bilibili.com' +url=base_url+'/'+uid+'/video' +path='chromedriver.exe' +browser=webdriver.Chrome(path) +browser.get(url) +time.sleep(2) +detial_url_list = [] +html = BeautifulSoup(browser.page_source) +last_page=html.find('div',id='submit-video-list').find('ul',class_='be-pager').find_all('li')[-2].find('a').text +# [-2].find('a').text +print(last_page) + +for a_label in html.find('div', id='submit-video-list').find_all('a',attrs={'target': '_blank', 'class': 'title'}): + if (a_label['href'] != None): + detial_url_list.append('https:' + a_label['href']) + +print(detial_url_list) +# print(url) +# headers={ +# 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', +# } +# +# response=requests.get(url=url,headers=headers) +# response.encoding='UTF-8' +# print(response.text) +# tree = etree.HTML(response.text) +# vedio_url_list=tree.xpath('//div[@class="s-space"]//div[@id="video-list-style"]//ul[@class="clearfix cube-list"]/li/a/@href') +# print(vedio_url_list) \ No newline at end of file