온라인 자습서를 기반으로 일부 웹 스크래핑 코드를 작성했으며 오류가 발생했습니다. 내 코드는 온라인에있는 내용과 거의 일치하지만 여전히 오류가있는 것 같습니다. 누군가 제발 도와 줄 수 있어요. 오류 유형에 따라 파일 이름과 경로와 관련이있는 것으로 보입니다. 여러 가지 조합을 시도했지만 여전히 오류가 발생하고 있습니다.아름다운 스프를 사용하여 파이썬으로 웹 스크래핑하는 프로그램에서 오류가 발생했습니다.
아래 코드를 복사하십시오. 당신이 당신의 오류를 게시되지 않은 것처럼
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38?Tpk=graphics%20cards'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
containers = page_soup.finaAll("div", {"class":"item-container"})
filename = "C:\\Users\\_Alekhine_\\Python\\products.csv"
f = open(filename, "w")
headers = "brand, product_name, shipping\n"
f.write(" ")
for container in containers:
brand = container.div.div.a.img["title"]
title_container = container.findAll("a", {"class": "item-title"})
product_name = title_container[0].text
shipping_container = container.findAll("li", {"class": "price-ship"})
shipping = shipping_container[0].text.strip()
print("brand: " + brand)
print("product_name: " + product_name)
print("shipping: " + shipping)
f.write(brand + "" + product_name.replace(",", "") + "" + shipping + "\n")
f.close()
어떤 오류가 발생하고 있습니까? 언급 할 중요한 것이 있다고 생각하지 않습니까? –