-
-
Save DavidCrash/7d7237db61856934895c77d3c858bb1c to your computer and use it in GitHub Desktop.
Python , Scrape Redbubble's sitemap to get the most popular searches etc..
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
#Scrape Redbubble's sitemap to get the most popular searches etc.. | |
#XIT07 | |
#Python | |
import requests, csv | |
from bs4 import BeautifulSoup | |
from datetime import datetime | |
today = datetime.now() | |
url = 'https://www.redbubble.com/sitemap/new_works_00001.xml' | |
def datas(url): | |
r = requests.get(url) | |
soup = BeautifulSoup(r.text, 'lxml') | |
data = soup.find_all('url') | |
return {i.find('loc').text: i.find('lastmod').text if i.find('lastmod') else None for i in data} | |
data = datas(url) | |
with open(today.strftime('%h_%Y-%m-%d_%H-%M-%S')+'.csv', 'w', newline='', encoding='utf-8') as file: | |
writer = csv.writer(file) | |
writer.writerow(['url', 'lastmod']) | |
for i in data: | |
info = {'url': i, 'lastmod': data[i]} | |
print(f'parsing {info}') | |
writer.writerow(list(info.values())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment