I am trying to load javascript and parse this website. I have the code below that, based on what I have come across, should work. I keep getting the following error message when I compile however.
Traceback (most recent call last):
File "C:\Users\herte_x6izw1s\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\herte_x6izw1s\anaconda3\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\herte_x6izw1s\PycharmProjects\search_all\search_all\my_app\views.py", line 68, in home
for google_post in google_initiate(request):
File "C:\Users\herte_x6izw1s\PycharmProjects\search_all\search_all\my_app\views.py", line 646, in google_initiate
response.html.render()
File "C:\Users\herte_x6izw1s\anaconda3\lib\site-packages\requests_html.py", line 586, in render
self.browser = self.session.browser # Automatically create a event loop and browser
File "C:\...\requests_html.py", line 727, in browser
self.loop = asyncio.get_event_loop()
File "C:\...\lib\asyncio\events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
Exception Type: RuntimeError at /
Exception Value: There is no current event loop in thread 'Thread-1'.
Exception Type: RuntimeError at /
Exception Value: There is no current event loop in thread 'Thread-1'.
I am really new to Requests-HTML and don't understand what this could be due to. I have been doing some research but everything doesn't seem very relevant to what I am doing and everything seems to be using something called "async". How do I fix this error? Thanks in advance!
import requests
from bs4 import BeautifulSoup
def home(request):
form = SearchForm(request.POST or None)
if form.is_valid():
form.save()
if request.POST:
if 'Google' in websites:
for google_post in google_initiate(request):
post_website = 'Google'
post_parse_page = ''
post_title = ''
post_url = ''
post_second_website = ''
post_second_url = ''
post_second_image_url = ''
post_price = 'n/a'
post_sort_by = ''
post_rating_quantity = ''
post_image_url
google_final_postings.append((post_title, post_url, post_price, post_image_url, post_rating, post_rating_quantity, post_website, post_second_website, post_second_url, post_second_image_url, post_parse_page, post_sort_by))
context['form'] = form
return render(request, 'home.html', context)
def google_initiate(request):
form = SearchForm(request.POST or None)
if form.is_valid():
url = 'https://www.google.com/search?biw=1866&bih=1043&tbm=shop&q=desk&tbs=mr:1,price:1,ppr_min:,ppr_max:,avg_rating:None'
session = HTMLSession()
response = session.get(url)
response.html.render()
print(response.html)
google_parsed = response.html.find('.sh-dgr__gr-auto.sh-dgr__grid-result')
response.close()
session.close()
return google_parsed