Arafath10 commited on
Commit
5f74ea1
1 Parent(s): 4454b97

Update scraper.py

Browse files
Files changed (1) hide show
  1. scraper.py +16 -12
scraper.py CHANGED
@@ -97,16 +97,20 @@ class Scraper:
97
 
98
  @staticmethod
99
  async def scrape(url):
100
- headers = {'User-Agent': 'Mozilla/5.0'}
101
- response = requests.get(url)
102
- soup = BeautifulSoup(response.content, 'html.parser')
103
-
104
- title = Scraper.get_title(soup)
105
- links = Scraper.get_links(soup)
106
- text_content = Scraper.get_text_content(soup)
107
-
108
- if not links:
109
- print("Running alternative scrapper")
 
 
 
 
 
110
  links, text_content = await Scraper.power_scrapper_2(url)
111
-
112
- return {"title": title, "URL": links, "Content": text_content}
 
97
 
98
  @staticmethod
99
  async def scrape(url):
100
+ try:
101
+ headers = {'User-Agent': 'Mozilla/5.0'}
102
+ response = requests.get(url)
103
+ soup = BeautifulSoup(response.content, 'html.parser')
104
+
105
+ title = Scraper.get_title(soup)
106
+ links = Scraper.get_links(soup)
107
+ text_content = Scraper.get_text_content(soup)
108
+
109
+ if not links:
110
+ print("Running alternative scrapper")
111
+ links, text_content = await Scraper.power_scrapper_2(url)
112
+
113
+ return {"title": title, "URL": links, "Content": text_content}
114
+ except:
115
  links, text_content = await Scraper.power_scrapper_2(url)
116
+ return {"title": title, "URL": links, "Content": text_content}