简体   繁体   English

地理定位网站的 Python 网页抓取

[英]Python web scraping of a geolocated website

I'm trying to web scrape a website that requests users to share their location so it adapts the contents to the clients' country.我正在尝试抓取一个网站,该网站要求用户分享他们的位置,以便它根据客户所在的国家/地区调整内容。

To do so, when I visit the site with Firefox a browser's pop up is displayed asking for that permission.为此,当我使用 Firefox 访问该站点时,会显示一个浏览器弹出窗口,要求获得该权限。

When scraping with Python I open the website with urllib.使用 Python 抓取时,我使用 urllib 打开网站。 Is there any way I can post or send my coordinates so I get the correct geolocated website?有什么方法可以发布或发送我的坐标,以便获得正确的地理定位网站?

Thanks.谢谢。

BR, BR,

d. d.

Manually sumbit your data by browsing the website.通过浏览网站手动汇总您的数据。 Then check your post requests in your browser's developer tools.然后在浏览器的开发人员工具中检查您的发布请求。 Store that information in a dictionary like shown below with data .将该信息与data一起存储在如下所示的字典中。

data = { "text": text }

Then use that to make a post request.然后使用它来发出帖子请求。 req=urllib2.Request(url,urllib.urlencode(data), headers)

And then get your response.然后得到你的回应。

response = urllib2.urlopen(req).read()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM