私はScrapyの経験はまだありませんが、私はPython Web Scrapingプロジェクトの途中です。私はスクラップにBeautifulSoupを使用しています。
私はコードの一部を書いています。これはタイトル、エピソード、サムネイルをすべて取得し、後で処理するために新しいページへのリンクを読み込みます。もっと問題がある場合は、メッセージを残してください)
from bs4 import BeautifulSoup
from urllib import request
url = "http://getanime.to/recent"
h = {'User-Agent': 'Mozilla/5.0'}
req = request.Request(url, headers=h)
data = request.urlopen(req)
soup = BeautifulSoup(data)
# print(soup.prettify()[:1000]) # For testing purposes - should print out the first 1000 characters of the HTML document
links = soup.find_all('a', class_="episode-release")
for link in links:
# Get required info from this link
thumbnail = link.find('div', class_="thumbnail")["style"]
thumbnail = thumbnail[22:len(thumbnail)-3]
title = link.find('div', class_="title-text").contents[0].strip()
episode = link.find('div', class_="super-block").span.contents[0]
href = link["href"]
# print(thumbnail, title, episode, href) # For testing purposes
# Load the link to this episode for further processing
req2 = request.Request(href, headers=h)
data2 = request.urlopen(req2)
soup2 = BeautifulSoup(data2)
vid_sources = soup2.find('ul', class_="dropdown-menu dropdown-menu--top video-sources")
# TODO repeat the above process to find all video sources
編集:上記のコードはpython3用です。明確にするために。
こんにちは@Nietvoordekat、クイック依存と上記のコードをありがとう。しかし何らかの理由で私のために働いていないようですね? ありがとう - チーズ – Cheese
[Beautifulsoupがインストールされていること](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)を確認してください。また、私は、 'from urllib import request'の部分はpython3を使っているときだけ動作すると信じています。どのバージョンのPythonを使用していますか?あなたはどんなエラーを出していますか? – Nietvoordekat
現在、明確なエラーはなく、実行すると何も表示されません。以前は2.7を使用していたのでリクエストが正しくインポートされていない問題がありましたが、今は3.6を使用しています。 – Cheese