#-*-coding:utf-8-*-ImportRequestsImportOSImportCSVImport TimeImportRandombase_url='http://api-t.iqiyi.com/feed/get_feeds?authcookie= 97rrnhwyza35luddm35yh4x5m2vv9djtuoufhaefvindjg17woo5em1se5vgm2vqn8sosb24&device_id= A35b964e5084125fb7dfab30205fe32b&m_device_id=969312df66b3063f0ad005ebce2181f1&agenttype=118&wallid =214740047&feedtypes=1%2c7&count=20&top=1&hasrecomfeed=1&needtotal=1&basetvid= 646605300&version=1&qypid=01010011010000000000&isvideopage=true&tvid=646605300&categoryid= 2&albumid=206289501&upordown=1&snstime={snstime}&t={t}&'Cookies= {'Cookies':'XXX'}headers= {'user-agent':'XXX'}resp= Requests.get (Base_url.format (T=int (Time.time () *1000), Snstime=int (Time.time ())), Headers=headers, cookies=cookies) Jsondata=Resp.json () data= Jsondata.get ("Data") Feeds= Data.get ('Feeds') Feedid="'Path= OS.GETCWD () +"/laozichuanqi.csv"CSVFile= Open (Path,'A +', encoding='Utf-8', newline="') Writer=Csv.writer (CSVFile) Writer.writerow (('name','Description')) Feedid="' forFeedinchFeeds:feedid= Feed.get ("Feedid") name= Feed.get ("name") Description= Feed.get ("Description") Print(name+"--"+description) Writer.writerow ((name, description))#print (Feedid)URL = base_url+"Feedid={feedid}" forIinchRange (105): Realurl= Url.format (Feedid=feedid, T=int (Time.time () *1000+random.random () *1000), Snstime=int (Time.time () +random.random () *100)) Resp= Requests.get (Realurl, Headers=headers, cookies=cookies) Jsondata=Resp.json () data= Jsondata.get ("Data") Feeds= Data.get ('Feeds') Print(Feedid)Print(len (feeds))Print(Realurl) time.sleep (15) #exit () ifData.get ("counts") ==0: Break forFeedinchFeeds:feedid= Feed.get ("Feedid") Print(feedid) name= Feed.get ("name") Description= Feed.get ("Description") Print(Name +"--"+description) Writer.writerow ((name, description)) Csvfile.close ()
The above code has some problems:
For example, a crawl loops and no longer crawls down.
Problem finder ...
Not to be continued ...
Python crawls Iqiyi "Laozi legend" review data