scrap n images depends on argv param
This commit is contained in:
parent
a27a7e612a
commit
1f4a2d9dfc
@ -3,8 +3,12 @@ from bs4 import BeautifulSoup
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
import os
|
import os
|
||||||
import csv
|
import csv
|
||||||
|
import sys
|
||||||
|
|
||||||
ROOT_URL = "https://myanimelist.net/character.php"
|
if len(sys.argv) > 1:
|
||||||
|
IMG_N = int(sys.argv[1])
|
||||||
|
else:
|
||||||
|
IMG_N = 50
|
||||||
|
|
||||||
def get_page_xpath_result(url, xpath_str):
|
def get_page_xpath_result(url, xpath_str):
|
||||||
HEADERS = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
|
HEADERS = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
|
||||||
@ -19,6 +23,12 @@ def createDirectory(path):
|
|||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
print(f"The {path} is created!")
|
print(f"The {path} is created!")
|
||||||
|
|
||||||
|
n = IMG_N // 50
|
||||||
|
|
||||||
|
for i in range(n):
|
||||||
|
ROOT_URL = f'https://myanimelist.net/character.php?limit={(i)*50}'
|
||||||
|
print(ROOT_URL)
|
||||||
|
|
||||||
character_links = get_page_xpath_result(ROOT_URL, '//div[@class="information di-ib mt24"]/a/@href')
|
character_links = get_page_xpath_result(ROOT_URL, '//div[@class="information di-ib mt24"]/a/@href')
|
||||||
character_names = get_page_xpath_result(ROOT_URL, '//div[@class="information di-ib mt24"]/a')
|
character_names = get_page_xpath_result(ROOT_URL, '//div[@class="information di-ib mt24"]/a')
|
||||||
character_names = [link.text for link in character_names]
|
character_names = [link.text for link in character_names]
|
||||||
|
Loading…
Reference in New Issue
Block a user