我是Python编程的新手,我正在Udemy网站的课程中学习它。在其中一个视频(解析汤)中,讲师编写了一些代码并得到了结果。但是问题是,每当我想在计算机上运行相同的代码时,都不会得到与指导者相同的结果。实际上结果什么都没有。我上传了教师代码和结果的屏幕截图。这是我的代码如下:您能帮我找到解决方法吗?
from bs4 import BeautifulSoup
import requests
search = input("what do you want to search : ")
params = {"q": search}
r = requests.get("http://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.find("a").attrs["href"]
if item_text and item_href:
print(item_text)
print(item_href)
我想我找到了解决方案,以及代码未给我任何答案的原因。我来自伊朗,互联网服务受到控制,Facebook,Youtube等某些网站被禁止和阻止。还有很多其他网站。由于这个问题,人们已经习惯了使用VPN服务,并且当我将Windows连接到任何VPN并运行代码时,代码运行正常,没有任何问题。