#coding: utf-8
import urllib
import urllib2
import re
def gettiebalistnumbers(name):
url="http://tieba.baidu.com/f?"
headers = {"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")
response = urllib2.urlopen(request)
data = response.read()
restr="<span class=\"card_infoNum\">([\s\S]*?)</span>"
regex = re.compile(restr, re.IGNORECASE)
mylist = regex.findall( data)
tienumbers= mylist[0].replace(",","")
tienumbers=eval(tienumbers)
return tienumbers
回傳資訊:
D:\Python\py2.7\installpath\python27.exe E:/Py基礎/py練習/yincheng爬蟲/tieba/1tieba.py
Process finished with exit code 0
環境:python2.7
PyCharm Community Edition 2020.1.3 x64

uj5u.com熱心網友回復:
python該換版本了uj5u.com熱心網友回復:
你沒呼叫這個函式吧轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/276377.html
上一篇:一道爬蟲題,抓取不到想要的內容
