How to scrape webpage by setting a different location than that of localhost?

167 views Asked by At

I was trying to scrape Bing news. When I access health news directly I get health news specific for U.S. visitors. When I access it in localhost using Goutte it gives results specific to India (which is my location) . Is there some way to get U.S. specific news while scraping?

I have set the user agent to make sure it is not a problem:

$client = new Client();
$client->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36');

I can't think of any other difference that can cause this issue.

2

There are 2 answers

0
Bader On

You didn't provide details so I might be wrong maybe you just need to send cookies with your request . First check your browser cookies and see if the values are affecting on the website if the cookies is the issue you can use this code (if you are using curl) :

//incoming cookies path
curl_setopt( $ch, CURLOPT_COOKIEJAR, '');
//your cookie file path 
curl_setopt( $ch, CURLOPT_COOKIEFILE, '' );
0
ilyazub On

Pass the cc=US parameter in Bing URL to explicitly find news in the USA.

https://www.bing.com/news/search?q=health+news&cc=US