これは私の最初のPythonプロジェクトです。これはかなりYouTubeの動画に続いて書きました。十分な知識はありませんが、私はコーディングの基礎を持っていると思います。私はクロール各ページから Pythonでウェブサイトをクロールした後に特定のデータを取得する
#importing the module that allows to connect to the internet
import requests
#this allows to get data from by crawling webpages
from bs4 import BeautifulSoup
#creating a loop to change url everytime it is executed
def creator_spider(max_pages):
page = 0
while page < max_pages:
url = 'https://www.patreon.com/sitemap/campaigns/' + str(page)
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
for link in soup.findAll('a', {'class': ''}):
href = "https://www.patreon.com" + link.get('href')
#title = link.string
print(href)
#print(title)
get_single_item_data(href)
page = page + 1
def get_single_item_data(item_url):
source_code = requests.get(item_url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
print soup
for item_name in soup.findAll('h6'):
print(item_name.string)
は、私が取得するためのコードは、この情報を強調したい:
http://imgur.com/a/e59S9そのソースコードです :
http://imgur.com/a/8qv7k
私は(私はsoup.findAllの属性を変更する必要がある数える何) get_single_item_data()functiomでは、すべての試みは無駄でした。これに関する助けは非常に感謝しています。 BS4ドキュメント
https://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-by-css-class
から
これはJavaScriptのサイトで、クロールできません。これらの種類のページをクロールするには、実際のブラウザをシミュレートする必要があります。セレンやファントムを試すことができます – sailesh