利用python編寫爬蟲爬取淘寶奶粉部分資料.1

post200發表於2021-09-09

import requests
import re
import pymysql.cursors

def getHTMLText(url):
kv = {'User-Agent':'Mozilla/5.0'} #反反爬蟲
try:
r = requests.get(url, headers = kv, timeout = 30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
print("error1")

def parsePage(ilt,html):
try:


infoList = []
for i in range(depth):
try:
換頁操作
        url = start_url + '&s=' + str(44*i)
        html = getHTMLText(url)
        parsePage(infoList,html)
    except:
        continue
printGoodsList(infoList)

main()

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/2249/viewspace-2799649/,如需轉載,請註明出處,否則將追究法律責任。

相關文章