Skip to content

Commit 7fc152d

Browse files
committedNov 15, 2024
feat: baidu search
1 parent e20fbae commit 7fc152d

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed
 

Diff for: ‎Headless/BaiduHot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import json
88

99
def BaiduHot(page_source):
10-
soup = BeautifulSoup(page_source, 'lxml')
11-
data = soup.find('textarea', id='hotsearch_data').get_text()
10+
html = BeautifulSoup(page_source, 'lxml')
11+
data = html.find('textarea', id='hotsearch_data').get_text()
1212
hotList = json.loads(data)['hotsearch']
1313

1414
for item in hotList:

Diff for: ‎Headless/BaiduSearch.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/local/bin/python3.9
2+
# -*- coding: utf-8 -*-
3+
# @Author skillnull
4+
# @Function 百度搜索结果
5+
6+
from bs4 import BeautifulSoup
7+
8+
def SearchResult(data):
9+
html = BeautifulSoup(data, 'html.parser')
10+
content = html.find('div', id='content_left')
11+
result = content.find_all('div', class_='result')
12+
13+
for item in result:
14+
res = item.find_all('h3',class_='c-title')
15+
title = res[0].a.get_text()
16+
print(title)

Diff for: ‎Headless/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from selenium.webdriver.common.keys import Keys
66
from selenium.webdriver.common.by import By
77
from BaiduHot import BaiduHot
8+
from BaiduSearch import SearchResult
89

910
fun_type = ''
1011

@@ -36,7 +37,7 @@ def main(skip_tips):
3637
search_input.send_keys(search_input_value)
3738
search_btn.send_keys(Keys.ENTER)
3839
time.sleep(1)
39-
print(web.title)
40+
SearchResult(web.page_source)
4041
else:
4142
fun_type = '1'
4243
main(True)

Diff for: ‎ZhiHu/Billboard.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
def billboard():
1111
url = 'https://www.zhihu.com/billboard'
1212
res = requests.get(url)
13-
soup = BeautifulSoup(res.text, 'lxml')
14-
data = soup.find('script',id='js-initialData').get_text()
13+
html = BeautifulSoup(res.text, 'lxml')
14+
data = html.find('script',id='js-initialData').get_text()
1515
hotList = json.loads(data)['initialState']['topstory']['hotList']
1616
# print(json.dumps(hotList, indent=2, ensure_ascii=False))
1717

0 commit comments

Comments
 (0)
Please sign in to comment.