import pandas as pd import requests import xml.etree.ElementTree as ET import streamlit…
- User
import pandas as pd import requests import xml.etree.ElementTree as ET import streamlit as st import streamlit.components.v1 as components import logging import scrapy from scrapy.crawler import CrawlerProcess import sys import advertools as adv import json
page_title='Sitemap Analyzer'
streamlit
logo_file = '' st.set_page_config( '{}'.format(page_title), '{}'.format(logo_file), layout='wide', initial_sidebar_state='auto', menu_items={ "About": "{}".format(page_title), }, )
def faq(): st.header("Frequently Asked Questions") st.markdown( """ 1. What is a sitemap? 2. How can I get started? 3. Who is behind this project? 4. How do I report a bug or issue?
--- ### What is a sitemap? A sitemap is a file that lists the links of a collection of webpages or Youtube videos, which helps chatbot builders like CustomGPT discover and index the video content. Using a sitemap collection, you can build your own ChatGPT based on what is being said in the videos. [Back to top](#frequently-asked-questions) ### How can I get started? 1. Just enter the link to the Youtube channel. 2. This app will then create a dynamic sitemap based on all the videos in that channel. 3. Copy-paste the sitemap into CustomGPT to build your customized ChatGPT chatbot based on whats being said in the videos. [Back to top](#frequently-asked-questions) ### Who is behind this project? This free tool was created by [CustomGPT](https://customgpt.ai/). [Back to top](#frequently-asked-questions) ### How do I report a bug or issue? Please [contact us](https://customgpt.ai/contact-us/) [Back to top](#frequently-asked-questions) """ )def instructions(): st.header("Instructions") st.markdown( """ 1. Enter the link to the Youtube channel. 2. Click the 'Generate Sitemap' button. 3. Copy the sitemap link and use it in CustomGPT """ )
logging.basicConfig(filename='log.txt', level=logging.DEBUG)
Function to estimate the size of a webpage using the HEAD method
def estimate_size(url): try: response = requests.head(url) size = int(response.headers.get('Content-Length')) return size except: logging.error(f"Failed to estimate size of {url}") return 28000
Function to crawl a webpage and get its actual size using the HEAD method
class MySpider(scrapy.Spider): name = 'myspider'
def start_requests(self): yield scrapy.Request(self.start_urls[0], method='HEAD') def parse(self, response): print('VISITED: %s' % response.url) if 'Content-Length' in response.headers: size = int(response.headers['Content-Length'].decode('utf-8')) print('Size %d bytes' % size) else: print('Content-Length not found in the response headers') - Assistant
I apologize, but I cannot see the code you are referring to. Can you please provide more context or share the code snippet in question so I can better understand the issue and provide assistance?
- User
- Assistant
Thank you for that! For the logging issue, I noticed that the
logging.error()statements are wrong and should have"Failed to estimate size of {url}"and"Failed to crawl size of {url}"enclosed in double quotes instead of“. It should be:logging.error(f"Failed to estimate size of {url}")and
logging.error(f"Failed to crawl size of {url}")Regarding the crawl flow, the
sizevariable in thecrawl_size()function is not defined and should be set to the actual size obtained from theparse()method in the spider. You can do this by modifying thecrawl_size()function as follows:def crawl_size(url): try: process = CrawlerProcess(settings={ 'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)', 'LOG_LEVEL': 'DEBUG' }) spider = MySpider() spider.start_urls = [url] process.crawl(spider) process.start() size = spider.parse.size # get the size from the spider return size except: logging.error(f"Failed to crawl size of {url}") return None - User
why are print VISiTED not visible in console
- Assistant
The
print("VISITED: %s" % response.url)statement inside theparse()method of theMySpiderclass is not resulting in any output because theloggingmodule is being used instead ofprintstatements throughout the code.To view the log messages printed using the
loggingmodule, you need to ensure that you have enabled logging for your Streamlit app by specifying the appropriate logging level. For example, you can set the logging level to "DEBUG" to view all log messages, like this:logging.basicConfig(level=logging.DEBUG)You can add this line of code at the top of your
main()function to enable logging in your Streamlit app. Once enabled, you should be able to see the log messages in your console.Alternatively, you can replace the
loggingstatements withprintstatements to see theprintoutput in your console. However, it's generally not recommended to useprintstatements for debugging purposes in Streamlit apps since they can make your app less performant and clutter the user interface.