We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
` def scrape_bing_search_results(query, num_results=5): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36' } url = f"https://cn.bing.com/search?q={query}"
response = requests.get(url, headers=headers) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') results = [] for i, result in enumerate(soup.select('.b_algo')[:num_results], 1): link_element = result.select_one('a') href = link_element['href'] title = link_element.text abstract_element = result.select_one('.b_caption p') abstract = abstract_element.get_text() if abstract_element else '' results.append({'href': href, 'title': title, 'abstract': abstract}) return results
def main(): parser = argparse.ArgumentParser(description='Bing Search Results Scraper') parser.add_argument('-q', '--query', help='The search query') parser.add_argument('-c', '--count', type=int, default=5, help='Number of results to retrieve') args = parser.parse_args() if not args.query: print(colored('query is empty', 'red')) exit() # 调用示例 search_results = scrape_bing_search_results(args.query, args.count) for result in search_results: print(colored(json.dumps(result, indent=2, ensure_ascii=False), 'yellow'))
if name == 'main': main() `
The text was updated successfully, but these errors were encountered:
No branches or pull requests
`
def scrape_bing_search_results(query, num_results=5):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
}
url = f"https://cn.bing.com/search?q={query}"
def main():
parser = argparse.ArgumentParser(description='Bing Search Results Scraper')
parser.add_argument('-q', '--query', help='The search query')
parser.add_argument('-c', '--count', type=int, default=5, help='Number of results to retrieve')
args = parser.parse_args()
if not args.query:
print(colored('query is empty', 'red'))
exit()
# 调用示例
search_results = scrape_bing_search_results(args.query, args.count)
for result in search_results:
print(colored(json.dumps(result, indent=2, ensure_ascii=False), 'yellow'))
if name == 'main':
main()
`
The text was updated successfully, but these errors were encountered: