[英]How to set header “Access-Control-Allow-Origin” to selenium Webdriver
[英]How to set Access-Control-Allow-Origin with js
从源“http://127.0.0.1:5500”访问“https://www.nseindia.com/api/option-chain-equities?symbol=RELIANCE”的 XMLHttpRequest 已被 CORS 政策阻止:对预检的响应请求未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
这是我的代码
const zonofne = async function handleSubmit() {
const headers = {
"Access-Control-Allow-Origin": "*",
};
await axios
.get("https://www.nseindia.com/api/option-chain-equities?symbol=RELIANCE", {
headers,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
};
zonofne();
您可以使用beautifulsoup
HTML 解析器:
import requests
from bs4 import BeautifulSoup
params = {
'q': 'what is the capital of india',
'hl': 'en'
}
url = 'https://www.google.com/search'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0'}
soup = BeautifulSoup(requests.get(url, params=params, headers=headers).content, 'html.parser')
capital = soup.select_one('[data-attrid="kc:/location/country:capital"]')
print(capital.text)
印刷:
New Delhi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.