【发布时间】:2020-12-05 15:03:38
【问题描述】:
背景:
接下来是一个 Udemy 教程,该教程正在解析来自 Bing 的一些信息。
它接受用户输入并将其用作搜索 Bing 的参数,返回它可以在第一页上找到的所有 href 链接
代码:
from bs4 import BeautifulSoup
import requests as re
search = input("Enter what you wanna search: \n")
params = {"q": search}
r = re.get("https://www.bing.com/search", params=params)
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find("ol",{"id":"b_results"})
links = results.findAll("li",{"class": "b_algo"})
for item in links:
item_text = item.find("a").text
item_href = item.href("a").attrs["href"]
if item_text and item_href:
print(item_text)
print(item_href)
else:
print("Couldn't find 'a' or 'href'")
问题:
它什么也不返回。该代码显然对他有用。我检查了id 和class 的名称以查看它们是否在制作视频后在 bing 上发生了更改,但它们仍然相同
"ol",{"id":"b_results"}
"li",{"class": "b_algo"}
有什么想法吗?我完全是网络抓取的菜鸟,但对 Python 来说是中等水平。
提前致谢!
【问题讨论】:
标签: python web-scraping beautifulsoup find