python - 除了代理ip,香港的服务器爬取国内网站还有更好的方法吗?
ringa_lee
ringa_lee 2017-04-18 10:19:01
0
3
829

我在做一只淘宝的爬虫,但是用的是香港的服务器,但是比较困惑:
因为每次爬淘宝的首页时候,就自动给我跳转到香港淘宝~~
导致源代码和内容都不一样~
请问如果遇到这种情况要怎么处理呢?

简单来说,比如采集58同城
如果我是泉州的,我想采集北京的,要怎么采集?

因为我用我的ip打开会总跳转到北京,但是直接想采集58首页的


?
![图片上传中...]

ringa_lee
ringa_lee

ringa_lee

reply all(3)
洪涛

Disable redirection, take requests as an example:

r = requests.get('http://github.com/', allow_redirects=False)
r.status_code  # 302
r.url  # http://github.com, not https.
r.headers['Location']  # https://github.com/ -- the redirect destination
洪涛

If you want to collect from Beijing, just enter the city name, but it is protected by PGTID

http://bj.58.com/?PGTID=0d000...

Jianyi uses selenium

迷茫

Sometimes the server will redirect based on the geographical location information corresponding to your IP. You should have no other way except to find a proxy. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!