少し前にお前らに相談したエロサイトのスクレイピングプログラムできたぞ!

1: 2chの人々 2021/07/14(水) 16:41:46.672 ID:F/llZ8Ur0
採点してくれ

引用元: ・少し前にお前らに相談したエロサイトのスクレイピングプログラムできたぞ!

2: 2chの人々 2021/07/14(水) 16:42:12.646 ID:ElL6+eM80
成果物をZIPで送ってくれ

3: 2chの人々 2021/07/14(水) 16:42:19.929 ID:F/llZ8Ur0
ちなpython

4: 2chの人々 2021/07/14(水) 16:42:44.896 ID:F/llZ8Ur0
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from time import sleep
import csv

HEADER = [‘動画タイトル’,’再生時間’, ‘画像URL’, ‘動画ページURL’,’画質’, ‘閲覧数’, ‘投稿日’, ‘高評価率’]

browser = webdriver.Chrome(ChromeDriverManager().install())

#検索キーワードを入力
keyword = ‘おっぱい’
#検索開始ページ
page = 1
#検索するページ数
max_page = 100

def get_url(keyword,page=1):
url = ‘https://www.tokyomotion.net/search?search_query={}&search_type=videos&type=public&page={}’.format(keyword,page)
return url

if __name__ == “__main__”:
while page <= 100:
url = get_url(keyword,page)
browser.get(url)
contents = browser.find_elements_by_class_name(‘col-sm-4.col-md-3.col-lg-3’)

with open(‘motion.csv’, ‘a’, encoding=’utf-8′) as f:
writer = csv.writer(f)
writer.writerow(HEADER)

for content in contents:
title = content.find_element_by_class_name(‘video-title’)
time = content.find_element_by_class_name(‘duration’)
post_date = content.find_element_by_class_name(‘video-added’)
views = content.find_element_by_class_name(‘video-views’)
heart = content.find_element_by_class_name(‘video-rating’)
heart_count = heart.find_element_by_tag_name(‘b’)
image = content.find_element_by_class_name(‘img-responsive ‘).get_attribute(‘src’)
link = content.find_element_by_class_name(‘thumb-popu’).get_attribute(‘href’)
try:
content.find_element_by_class_name(‘hd-text-icon’)
quality = ‘HD’
except:
quality = ‘SD’

title_csv = title.text
time_csv = time.text
image_csv = image
link_csv = link
quality_csv = quality
pv_csv = views.text
date_csv = post_date.text
evaluation_csv = heart_count.text

row = [title_csv,time_csv,image_csv,link_csv,quality_csv,pv_csv,date_csv,evaluation_csv]
writer.writerow(row)

sleep(10)
page += 1

13: 2chの人々 2021/07/14(水) 16:52:10.560 ID:U3MR66nv0
>>4
これ改行多すぎ規制にならないんだ

5: 2chの人々 2021/07/14(水) 16:45:02.239 ID:F/llZ8Ur0
https://qiita.com/kawamasa/items/730969d164a6ab6d90c8
↑を参考にしてExcelでサムネイル込みで一気に閲覧できるからストレスフリーだぜ!
※画像読み込みまでかなりじかんかかるけど

6: 2chの人々 2021/07/14(水) 16:45:35.438 ID:kMaQ51gG0
>>5
ストレスだらけじゃん

8: 2chの人々 2021/07/14(水) 16:46:15.526 ID:F/llZ8Ur0
>>5
ページめくりの必要がないからストレスフリーなの!

7: 2chの人々 2021/07/14(水) 16:45:45.070 ID:F/llZ8Ur0
ソースコード渡すのに適した方法無いのかな

9: 2chの人々 2021/07/14(水) 16:47:00.561 ID:LrfyGc/q0
おっpython

10: 2chの人々 2021/07/14(水) 16:47:26.356 ID:cPZA0k65a
出来上がるまでに何回抜いた?

17: 2chの人々 2021/07/14(水) 16:57:03.377 ID:F/llZ8Ur0
>>10
我慢したよ!これから抜く!

11: 2chの人々 2021/07/14(水) 16:47:39.527 ID:F/llZ8Ur0
インデントがおかしいどう渡せばいいんだ

12: 2chの人々 2021/07/14(水) 16:51:21.656 ID:dgkWUCi8M
ノートン先生大激怒

14: 2chの人々 2021/07/14(水) 16:54:31.605 ID:F/llZ8Ur0
こんな風に一覧表示できるの
https://imgur.com/OQQMmNv.jpg

15: 2chの人々 2021/07/14(水) 16:54:43.806 ID:qwCtNHGb0
配列rowに入れる値を一旦変数にする必要なくないか?

16: 2chの人々 2021/07/14(水) 16:56:23.421 ID:F/llZ8Ur0
>>15
こういう意見マジ助かる
調べながらやってると無駄な事に気付かないもんだな…。
修正してくる

18: 2chの人々 2021/07/14(水) 16:57:04.821 ID:nI1e+p0k0
pythonで実行すればいいの?

20: 2chの人々 2021/07/14(水) 17:00:56.230 ID:F/llZ8Ur0
>>18
そうわよ!
そうすると同じディレクトリにCSVファイルが作られるからそのファイルをExcelとかで開くとシコりやすい

19: 2chの人々 2021/07/14(水) 16:59:36.721 ID:F/llZ8Ur0
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from time import sleep
import csv

HEADER = [‘動画タイトル’,’再生時間’, ‘画像URL’, ‘動画ページURL’,’画質’, ‘閲覧数’, ‘投稿日’, ‘高評価率’]

browser = webdriver.Chrome(ChromeDriverManager().install())

#検索キーワードを入力
keyword = ‘おっぱい’
#検索開始ページ
page = 1
#検索するページ数
max_page = 100

def get_url(keyword,page=1):
url = ‘https://www.tokyomotion.net/search?search_query={}&search_type=videos&type=public&page={}’.format(keyword,page)
return url

if __name__ == “__main__”:
while page <= 3:
url = get_url(keyword,page)
browser.get(url)
contents = browser.find_elements_by_class_name(‘col-sm-4.col-md-3.col-lg-3’)

with open(‘motion1.csv’, ‘a’, encoding=’utf-8′) as f:
writer = csv.writer(f)
writer.writerow(HEADER)

for content in contents:
title = content.find_element_by_class_name(‘video-title’).text
time = content.find_element_by_class_name(‘duration’).text
date = content.find_element_by_class_name(‘video-added’).text
views = content.find_element_by_class_name(‘video-views’).text
heart = content.find_element_by_class_name(‘video-rating’)
heart_count = heart.find_element_by_tag_name(‘b’).text
image = content.find_element_by_class_name(‘img-responsive ‘).get_attribute(‘src’)
link = content.find_element_by_class_name(‘thumb-popu’).get_attribute(‘href’)
try:
content.find_element_by_class_name(‘hd-text-icon’)
quality = ‘HD’
except:
quality = ‘SD’

row = [title,time,image,link,quality,views,date,heart_count]
writer.writerow(row)

sleep(10)
page += 1
修正したわよ!

21: 2chの人々 2021/07/14(水) 17:02:29.742 ID:F/llZ8Ur0
間違えた

22: 2chの人々 2021/07/14(水) 17:04:48.450 ID:F/llZ8Ur0
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from time import sleep
import csv

HEADER = [‘動画タイトル’,’再生時間’, ‘画像URL’, ‘動画ページURL’,’画質’, ‘閲覧数’, ‘投稿日’, ‘高評価率’]

browser = webdriver.Chrome(ChromeDriverManager().install())

#検索キーワードを入力
keyword = ‘おっぱい’

#検索開始ページ
page = 1

#検索するページ数
max_page = 1

#保存するCSVファイル名
save_csv = ‘motion8.csv’

def get_url(keyword,page=1):
url = ‘https://www.tokyomotion.net/search?search_query={}&search_type=videos&type=public&page={}’.format(keyword,page)
return url

if __name__ == “__main__”:
while page <= max_page:
url = get_url(keyword,page)
browser.get(url)
contents = browser.find_elements_by_class_name(‘col-sm-4.col-md-3.col-lg-3’)

with open(save_csv, ‘a’, encoding=’utf-8′) as f:
writer = csv.writer(f)
writer.writerow(HEADER)

for content in contents:
title = content.find_element_by_class_name(‘video-title’).text
time = content.find_element_by_class_name(‘duration’).text
date = content.find_element_by_class_name(‘video-added’).text
views = content.find_element_by_class_name(‘video-views’).text
heart = content.find_element_by_class_name(‘video-rating’)
heart_count = heart.find_element_by_tag_name(‘b’).text
image = content.find_element_by_class_name(‘img-responsive ‘).get_attribute(‘src’)
link = content.find_element_by_class_name(‘thumb-popu’).get_attribute(‘href’)
try:
content.find_element_by_class_name(‘hd-text-icon’)
quality = ‘HD’
except:
quality = ‘SD’

row = [title,time,image,link,quality,views,date,heart_count]
writer.writerow(row)

sleep(10)
page += 1

Author: 暇人さん

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です