import requests
 
def crawl_web(keyword, max_pages):
    base_url = "https://www.baidu.com/s?wd="
    response = requests.get(base_url + keyword)
    print(f"Status code: {response.status_code}")
 
    if response.status_code == 200:
        print("Successfully connected to the webpage.")
        # 此处省略处理response的代码,因为问题中没有提及具体的处理逻辑
    else:
        print("Failed to connect to the webpage.")
 
keyword = "Python"  # 替换为你想搜索的关键词
max_pages = 10  # 设置你想要获取搜索结果的最大页数
crawl_web(keyword, max_pages)这段代码使用了requests模块来发送HTTP GET请求到百度搜索引擎,并将搜索关键词和页数作为参数传递。如果请求成功,它会打印出响应的状态码,然后可以进一步处理响应的内容。如果请求失败,它会打印出错误信息。这个简单的例子展示了如何使用Python进行基本的网络爬虫操作。