Home > other >  , every brother for help: help me see why couldn't grab the data
, every brother for help: help me see why couldn't grab the data

Time:04-16

# coding: utf-8
The import urllib
The import urllib2
The import re



Def gettiebalistnumbers (name) :
Url="http://tieba.baidu.com/f?"
Headers={the user-agent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0);" }
Word={" kw ": name}
Word=urllib. Urlencode (word)
Url=url + word
Request=urllib2. Request (url, headers=headers)

Request. Add_header (" Connection ", "keep alive -")
The response=urllib2. Urlopen (request)
Data=(https://bbs.csdn.net/topics/response.read)


Restr="& lt; Span class=\ "card_infoNum " & gt; ([\ s \ s] *? "
The regex=re.com running (restr, re. IGNORECASE)
Mylist=regex. The.findall (data)
Tienumbers=mylist [0]. Replace (", ", "")
Tienumbers=eval (tienumbers)
Return tienumbers




Return information:
D: \ Python \ py2.7 \ installpath \ python27 exe E:/Py base/Py practice/yincheng crawler/tieba/1 tieba. Py

The Process finished with exit code 0



Environment: python2.7
PyCharm Community Edition 2020.1.3 x64





CodePudding user response:

Python was changing the version

CodePudding user response:

You didn't call this function