I'm trying to create a script in python using requests module to scrape the title of different jobs from a website. To parse the title of different jobs I need to get the relevant response from that site first so that I can process the content using BeautifulSoup. However, When I run the following script, I can see that the script produces gibberish which literally do not contain the titles I look for.
website link (In case you don't see any data, make sure to refresh the page
)
I've tried with:
import requests
from bs4 import BeautifulSoup
link = 'https://www.alljobs.co.il/SearchResultsGuest.aspx?'
query_string = {
'page': '1',
'position': '235',
'type': '',
'city': '',
'region': ''
}
with requests.Session() as s:
s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
s.headers.update({"Referer":"https://www.alljobs.co.il/SearchResultsGuest.aspx?page=2&position=235&type=&city=®ion="})
res = s.get(link,params=query_string)
soup = BeautifulSoup(res.text,"lxml")
for item in soup.select(".job-content-top [class^='job-content-top-title'] a[title]"):
print(item.text)
I even tried like this:
import urllib.request
from bs4 import BeautifulSoup
from urllib.parse import urlencode
link = 'https://www.alljobs.co.il/SearchResultsGuest.aspx?'
query_string = {
'page': '1',
'position': '235',
'type': '',
'city': '',
'region': ''
}
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36",
"Referer":"https://www.alljobs.co.il/SearchResultsGuest.aspx?page=2&position=235&type=&city=®ion="
}
def get_content(url,params):
req = urllib.request.Request(f"{url}{params}",headers=headers)
res = urllib.request.urlopen(req).read()
soup = BeautifulSoup(res,"lxml")
for item in soup.select(".job-content-top [class^='job-content-top-title'] a[title]"):
yield item.text
if __name__ == '__main__':
params = urlencode(query_string)
for item in get_content(link,params):
print(item)
How can I fetch the title of different jobs using requests?
PS Browser simulator is not an option here to do the task.