I wanna scrape some details from a main_url in which for each company it has another url for each company and get credentials of a each company from which there are some elements like company name,phone,fax,website..etc. I have write the code using beautifulsoup and requests and also got the credentials(but got only for 52 companies) .After that it giving an error of javascript cause there is loadmore button. I want to get all companies details by crossing that loadmore button too.Only wanna do with requests and beautifulsoup. Don't want to use selenium for it.I'll be glad and thankful for getting help. Here is my code till where I get good result but only having problem with load more button.
from time import time
from bs4 import BeautifulSoup
import urllib.request
import requests
import json
import time
parser = 'html.parser' # or 'lxml' (preferred) or 'html5lib', if installed
resp = urllib.request.urlopen("https://www.arabiantalks.com/category/1/advertising-gift-articles")
soup = BeautifulSoup(resp, parser, from_encoding=resp.info().get_param('charset'))
cnt=0
for links in soup.find_all('a', href=True):
url=(links['href'])
# print(url)
page=requests.get(url)
# print(page).
soup=BeautifulSoup(page.content,'html.parser')
# print(soup)
results=soup.find('div',class_='rdetails')
# print(results)
if results is not None:
# print(f"company_results: {results.text}")
Name=results.find('h1')
if Name is not None:
print(f"Comapny_name: {Name.text}")
else:
print(f"Comapny_name: Notfound")
address=results.find(attrs={'itemprop':'address'})
if address is not None:
# address.text.replace(" Address : ", "")
# print(type(f"Comapny_address: {address.text}"),"this type")
print((f"Comapny_address: {address.text[12:]}"))
else:
print(f"Comapny_address: Notfound")
phone=results.find(attrs={'itemprop':'telephone'})
if phone is not None:
print(f"Comapny_phone: {phone.text[16:]}")
else:
print(f"Comapny_phone: Notfound")
fax=results.find(attrs={'itemprop':'faxNumber'})
if fax is not None:
print(f"Comapny_fax: {fax.text[7:]}")
else:
print(f"Comapny_fax: Notfound")
email=results.find(attrs={'itemprop':'email'})
if email is not None:
print(f"Comapny_email: {email.text[9:]}")
else:
print(f"Comapny_email: Notfound")
website=results.find(attrs={'itemprop':'url'})
if website is not None:
print(f"Comapny_website: {website.text}")
else:
print(f"Comapny_website: Notfound")
cnt += 1
print(cnt)
print("="*100)
If anyone know the ideology could you please copy these code and do required modifications and post as reply again.So I would know where to change.I tried from many articles, but still struggling.This is first answer the final link I tried.Please help me with this issue I'm pretty new in web scraping. Thanks in advance...