我正在尝试使用请求模块在 python 中创建一个脚本,以从网站上抓取不同工作的标题。要解析不同工作的标题,我需要首先从该站点获得相关响应,以便我可以使用 BeautifulSoup 处理内容。但是,当我运行以下脚本时,我可以看到该脚本产生的乱码实际上不包含我要查找的标题。
网站链接( In case you don't see any data, make sure to refresh the page)
我试过:
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)
Run Code Online (Sandbox Code Playgroud)
我什至这样试过:
import urllib.request …Run Code Online (Sandbox Code Playgroud) python beautifulsoup web-scraping python-3.x python-requests