Home > other >  Python crawler JSONDecodeError: Expecting value: line 1 column 1 0 (char)
Python crawler JSONDecodeError: Expecting value: line 1 column 1 0 (char)

Time:04-19

Is there a big help to take a look at why I always make mistakes, baidu still can not find the answer


_ coding=utf-8 _ # _ * * _
The import requests, time, the random
The import OS
The from bs4 import BeautifulSoup
The import json
The from urllib. Parse the import urlencode

Base_url='https://weibo.com/? Category=1760 '
Headers={
'Host' : 'weibo.com',
'Referer:' https://weibo.com/',
'the user-agent' : 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
'X - Requested - With' : 'the XMLHttpRequest,
}


Def the get_page (page) :

RND=int (time. Time ())
Params={
6 ', 'ajwvr' : '
'category', '1760',
'page: page,
'lefnav' : '0',
'cursor' : ' ',
'__rnd: RND

}

Url=base_url + urlencode (params)
Res=requests. Get (url, headers=headers, params=params). The json ()

Try:
Time. Sleep (random. The random () * 2)
Res=requests. Get (url, headers=headers). Json ()
If res. Status_code==200:
Return res. Json ()
Except the Exception as e:
Print (' Error: ', e.a RGS)


If __name__=="__main__" :
For page in range (1, 3) :
Result=the get_page (page)
Weibo_images=the get_image (result)


  • Related