o
�#�g � @ s� d dl Z d dlmZ d dlZd dlmZ ddd�Zddd�Zed kr�d
Zeedd�Z e
d� e D ]*Ze
d
ed � �� e
ded � �� e
ded � �� e
ded � �� e
d� q0d
Zeedddd�Z
e
d� e
D ]*Ze
d
ed � �� e
ded � �� e
ded � �� e
ded � �� e
d� qke�d�Zee�Ze�e� e�e�Ze�e� ed d Ze�e�Ze�e� dd� ed D �Ze
e� dS dS ) � N)�
BeautifulSoup)� scholarly� c C s d| � dd�� �}ddi}tj||d�}|jdkr#td|j� �� g S t|jd �}g }d
}|jddd
�D ]V}||kr= |S |jddd
�} | rJ| � � nd}
| rZ| �d�rZ| �d�d nd}|jddd
�}|ri|� � nd}
|jddd
�}|rx|� � nd}|
|
||d�}|�
|� |d7 }q4|S )a'
Function to search Google Scholar using a simple keyword query.
Parameters:
query (str): The search query (e.g., paper title or author).
num_results (int): The number of results to retrieve.
Returns:
list: A list of dictionaries containing search results.
z%https://scholar.google.com/scholar?q=� �+�
User-Agent�sMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36��headers�� �(Failed to fetch data. HTTP Status code: �html.parserr �div�gs_ri��class_�h3�gs_rt�No title available�a�href�No link available�gs_a�No authors available�gs_rs�No abstract available��Title�Authors�Abstract�URL� N)�replace�requests�get�status_code�printr �text�find_all�find�get_text�append)�query�num_results�
search_urlr
�response�soup�results�count�item� title_tag�title�link�authors_tag�authors�abstract_tag�abstract�result_data� r<