code is shown in the figure:
-sharp -*- coding:utf-8 -*-
import webbrowser
import pyperclip
import sys
import bs4
import requests
search_target = pyperclip.copy("kkkk")
if len(sys.argv) > 1:
search_target = " ".join(sys.argv[1:])
else:
search_target = pyperclip.paste()
res_temp = "http://www.baidu.com/s?wd=" + search_target
webbrowser.open(res_temp)
res = requests.get(res_temp)
bsObj = bs4.BeautifulSoup(res.text, "html.parser")
print(bsObj)
-sharph3 = bsObj.findAll("h3", {"class":"t"})
-sharpprint(h3)
print("---1---")
div = bsObj.findAll("div", {"class":"result c-container "})
print(div)
print("---2---")
h3 = div.findAll("h3",{"class":"t"})
print(h3)
print("---3---")
the running result is as follows:
:
divh3
:
H3 is already a sub-tag under the div tag, so why can it be collected by div but not by H3?