Skip to content
This repository was archived by the owner on Mar 14, 2022. It is now read-only.

[General] 爬蟲 #386

@soniaasunn

Description

@soniaasunn

提交連結

程式碼

new_key = "https://www.google.com/search?q="+keyword+"&rlz=1C5CHFA_enTW819TW819&oq="+keyword+"&aqs=chrome..69i57j0i333.15346j0j7&sourceid=chrome&ie=UTF-8"
re2 = requests.get(new_key)
soup_google = BeautifulSoup(re2.text, "html.parser")
all_google = soup_google.findAll("div",{"class":"yuRUbf"}) 

#給出第三個連結
url_google = all_google[2].a["href"]
print(url_food_rec)

Screen Shot 2021-12-06 at 10 36 43 PM

錯誤訊息

Screen Shot 2021-12-06 at 10 33 46 PM

問題描述

  • 目的:想要爬取黃色框框裡的連結
  • 已嘗試方法:soup_google.findAll("div",{"class":"yuRUbf"}) 和soup_google.find("div",{"class":"g"}).find("div",{"class":"tF2Cfc"}).find("div",{"class":"yuRUbf"})
  • 結果:都為IndexError: list index out of range,不知道為什麼

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions