KOTA ITO

Generation

generate functionMon, 20 Mar 2023

beautiful soupで、XPATH「//*[@id="rso"]/div[1]/div/div/div[1]/div/a」に含まれるURL文字列を取得する。

def get_google_links(search_query): # using google to search r = requests.get("http://www.google.co.jp/search?q=" + search_query) data = r.text # parse html soup = BeautifulSoup(data, "lxml") all_divs = soup.find_all("a") links = [] for div in all_divs: if "http" in div['href']: links.append(div['href']) return links

Questions about programming?Chat with your personal AI assistant