-
-
Save peco2282/c7e42031eca0897c91150f22f4a9fdc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests | |
from bs4 import BeautifulSoup, Tag | |
url = "https://rtrp.jp/locations/332/categories/291/?order=retrip_score&page={}" | |
# 記事1枚当たり15店舗載っているので定数化。 | |
RANK = 15 | |
def check_bs4(text: str, time: int): | |
print(f"---Page {time + 1}---") | |
soup = BeautifulSoup(text, "html.parser") | |
for i in range(RANK): | |
elem: Tag = soup.select( | |
f"#mainWrap > div.mainContent > section.locationSpots > div.spotList > section:nth-child({2 * i + 1}) > div.spotListContentTop > h3 > a" | |
)[0] | |
print(i + 1, "店目") | |
print("name : ", elem.text.strip()) | |
print("site_url: ", elem.get("href")) | |
print("-------------------") | |
if __name__ == '__main__': | |
for i in range(5): | |
response = requests.get(url.format(i + 1)) | |
check_bs4(response.text, i) | |
# 念のため2秒開ける。 | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment