File tree 4 files changed +22
-5
lines changed
4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 7
7
import json
8
8
9
9
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 ()
12
12
hotList = json .loads (data )['hotsearch' ]
13
13
14
14
for item in hotList :
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 5
5
from selenium .webdriver .common .keys import Keys
6
6
from selenium .webdriver .common .by import By
7
7
from BaiduHot import BaiduHot
8
+ from BaiduSearch import SearchResult
8
9
9
10
fun_type = ''
10
11
@@ -36,7 +37,7 @@ def main(skip_tips):
36
37
search_input .send_keys (search_input_value )
37
38
search_btn .send_keys (Keys .ENTER )
38
39
time .sleep (1 )
39
- print (web .title )
40
+ SearchResult (web .page_source )
40
41
else :
41
42
fun_type = '1'
42
43
main (True )
Original file line number Diff line number Diff line change 10
10
def billboard ():
11
11
url = 'https://www.zhihu.com/billboard'
12
12
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 ()
15
15
hotList = json .loads (data )['initialState' ]['topstory' ]['hotList' ]
16
16
# print(json.dumps(hotList, indent=2, ensure_ascii=False))
17
17
You can’t perform that action at this time.
0 commit comments