0
私はウェブサイトを削り取ろうとしていますが、このコードを実行するとデータの半分(批評家のデータを含む)しか印刷されません。ここに私のスクリプトは次のとおりです。BeautifulSoupはすべてのデータを削っていません
from bs4 import BeautifulSoup
from urllib.request import urlopen
inputfile = "Chicago.csv"
f = open(inputfile, "w")
Headers = "Name, Link\n"
f.write(Headers)
url = "https://www.chicagoreader.com/chicago/best-of-chicago-2011-food-drink/BestOf?oid=4106228"
html = urlopen(url)
soup = BeautifulSoup(html, "html.parser")
page_details = soup.find("dl", {"class":"boccat"})
Readers = page_details.find_all("a")
for i in Readers:
poll = i.contents[0]
link = i['href']
print(poll)
print(link)
f.write("{}".format(poll) + ",https://www.chicagoreader.com{}".format(link)+ "\n")
f.close()
- は私のスクリプトスタイル間違ってますか?
- コードを短くするにはどうすればよいですか?
find_all
とfind
を使用すると、属性エラーが発生します。私は書類を読むが、理解していない。
シャヒンこんにちは、あなたはfind_allのと見つけるの短い例を提供してくださいすることができますか..? –
@ Mr.Bones、私は既にfindとfind_allの例を挙げました。上記をご覧ください。 – SIM