I want to scrape the web with Python and I am running into some problems. Here is my code:
from urllib import request
from bs4 import BeautifulSoup
pageURL="https://gamesnacks.com/embed/games/omnomrun"
rawPage=request.urlopen(pageURL)
soup=BeautifulSoup(rawPage, "html5lib")
content=soup.article
linksList=[]
for link in content.find_all('a'):
url=link.get("href")
img=link.get("src")
text=link.span.text
linksList.append({"url":"url","img":"img","text":"text"})
try:
url=link.get("href")
img=link.get("src")
text=link.span.text
linksList.append({"url":"url","img":"img","text":"text"})
except AttributeError:
pass
import json
with open("links.json","w",encoding="utf-8") as links_file:
json.dump(linksList,links_file,ensure_ascii=False)
print("the work is done")
It gives an error in
for link in content.find_all('a'):
I have already tried some online help but it didn't work out.
linksList.append({"url":"url","img":"img","text":"text"})seems suspicious for me BTW.