久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

網頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決

瀏覽:257日期:2022-08-06 14:43:40

問題描述

import urllib.requestimport reweb=urllib.request.urlopen(’https://www.gpyh.com/pricebuy/index?pageNum=1&hasStock=&goodsStandardId=1931&materialDictCode=&materialGroupCode=037001&diameter=&length=&brandId=&merchantId=’)neirong=web.read()def getPage(self,pageIndex): url = self.siteURL + '?pageNum=' + str(pageIndex) request = urllib2.Request(url) response = urllib2.urlopen(request) return response.read().decode(’gbk’)jiangrenhua=neirong.decode(’UTF-8’)RegularExpression=’<td>(.*)</td>’Valuable=re.findall(RegularExpression,jiangrenhua)information=[]for i in range(173): print(Valuable[i]

問題解答

回答1:

?pageNum=' + str(pageIndex)

這一個不就是你的頁碼控制嗎?登錄后才看到那就用cookie或者用戶名密碼模擬登錄后獲取

回答2:

httplib2基本應該是所有http請求的終結者了吧。

import httplib2import urllibhttp = httplib2.Http()url=’要獲取的地址’header={’Accept’:’text/html’, ’Accept-Encoding’:’gzip, deflate, sdch’, ’Accept-Language’:’zh-CN,zh;q=0.8’, ’Cache-Control’:’max-age=0’, ’Connection’:’keep-alive’, ’Cookie’:’cookie內容’, ’Upgrade-Insecure-Requests’:’1’, ’User-Agent’:’Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36’} #要有登陸狀態才能翻頁就要模擬登陸后把cookie放進去body_value={’username’:’test’,’password’:’123456’} #表單的所有內容body_value=urllib.urlencode(body_value) #utf8編碼response, content = http.request(url, ’GET’, headers=header,body=body_value) #GET或者POST方法response.encoding = ’utf-8’#content就是返回內容

標簽: Python 編程
主站蜘蛛池模板: 庄河市| 东阿县| 乾安县| 新平| 资兴市| 西乌| 白朗县| 枝江市| 房产| 和平县| 曲周县| 旬阳县| 仪征市| 中江县| 乌兰县| 汉寿县| 滦南县| 随州市| 察隅县| 台南县| 临汾市| 新余市| 西昌市| 陕西省| 闽清县| 淮北市| 瑞安市| 铁岭市| 利辛县| 朝阳县| 大城县| 昔阳县| 任丘市| 巴马| 普安县| 安吉县| 通州区| 钟祥市| 盖州市| 罗平县| 长海县|