Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问这个嵌入iframe是怎么解决跨域问题的呢? #89

Open
stormstone opened this issue Jul 30, 2019 · 3 comments
Open

请问这个嵌入iframe是怎么解决跨域问题的呢? #89

stormstone opened this issue Jul 30, 2019 · 3 comments

Comments

@stormstone
Copy link

把待爬取的页面通过iframe嵌入进来,是怎样给页面里的元素添加属性和控制的呢?

@speed
Copy link
Owner

speed commented Jul 30, 2019

代理,变成同域

@stormstone
Copy link
Author

代理,变成同域

我不太了解这方面,有什么学习资料吗,希望能指点一二,万分感谢!

@stormstone
Copy link
Author

找到了nginx反向代理的方法,谢谢指点!

    server {
        listen       8090;
        server_name  localhost;
		
		# 爬虫前端页面代理
		location ^~ /spider {
			rewrite ^/spider/(.*)$ /$1 break;
			root html/spider-front;
		}
		
		# 待爬取网站代理
		location / {
			add_header 'Access-Control-Allow-Origin' $http_origin;
			add_header 'Access-Control-Allow-Credentials' 'true';
			proxy_pass http://www.baidu.com;
		}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants