linux - Python encounters verification problems when grabbing public account articles
大家讲道理
大家讲道理 2017-05-16 13:33:44
0
4
651

Encountered verification problems when grabbing WeChat public account articles under Linux! ! ! ! ! ! ! !

This is the People’s Daily link I want to grab: http://mp.weixin.qq.com/profile?src=3×tamp=1492739045&ver=1&signature=bSSQMK1LY77M4O22qTi37cbhjhwNV7C9V4aor9HLhAvbGc2ybWX*qg3WqxntZ7iq0kvYe87oP pcSJKFdmGMx5g==
1: First of all, accessing on the browser is normal.
2: The access prompt under Linux requires verification. The following is a simple code

url = http://mp.weixin.qq.com/profile?src=3&timestamp=1492738883&ver=1&signature=bSSQMK1LY77M4O22qTi37cbhjhwNV7C9V4aor9HLhAvbGc2ybWX*qg3WqxntZ7iq2xTLUTfxAMzK79UGvalY1A==
response = urllib2.urlopen(url)
print response.read()

The results of the visit are as follows:

Additional explanation of how to obtain the link to the public account:
1: First visit the link: http://weixin.sogou.com/weixi...
2: Then obtain the link to the People's Daily public account. jump.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
習慣沉默

Can it be captured without simulating the request header? It is recommended to simulate the request header first and try again

某草草
# coding: utf-8

import requests

headers = {}
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'

url = 'http://mp.weixin.qq.com/profile?src=3&timestamp=1492739045&ver=1&signature=bSSQMK1LY77M4O22qTi37cbhjhwNV7C9V4aor9HLhAvbGc2ybWX*qg3WqxntZ7iq0kvYe87oPpcSJKFdmGMx5g=='
r = requests.get(url, headers=headers)
print r.text
淡淡烟草味

Now after adding the header to the request, the error returned is as follows. Please give me some more tips

習慣沉默

You can use request, the local environment is Mac OSX, python3.6.1

import requests

headers = {'user-agent' : 'Mozilla/5.0'}
respon = requests.get('http://mp.weixin.qq.com/profile?src=3&timestamp=1492831080&ver=1&signature=bSSQMK1LY77M4O22qTi37cbhjhwNV7C9V4aor9HLhAvbGc2ybWX*qg3WqxntZ7iqB7vsPUlOS3zhl-8n5FUODg==', headers = headers)
respon.encoding = 'utf-8'
print(respon.text)

The content is in the line with the red box

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template