資源簡介
亞馬遜爬蟲爬取商品評論價格 等信息保存成CSV格式。。。。
代碼片段和文件信息
import?requests
from?bs4?import?BeautifulSoup?as?bs
from?multiprocessing?import?Pool
import?pandas?as?pd
Hearder={
????‘Accept‘:‘text/htmlapplication/xhtml+xmlapplication/xml;q=0.9image/webp*/*;q=0.8‘
????‘Accept-Encoding‘:‘gzip?deflate?sdch‘
????‘Accept-Language‘:‘zh-CNzh;q=0.8‘
????‘Cache-Control‘:‘max-age=0‘
????‘Connection‘:‘keep-alive‘
????‘Host‘:‘www.amazon.cn‘
????‘Upgrade-Insecure-Requests‘:‘1‘
????‘User-Agent‘:‘Mozilla/5.0?(Windows?NT?6.1;?Win64;?x64)?AppleWebKit/537.36?(KHTML?like?Gecko)?Chrome/63.0.3239.84?Safari/537.36‘
}
session=requests.session()
session.headers=Hearder
def?write_data(dataid):#寫數(shù)據(jù)到csv
????print(“SAVE?id?of?goods:“?+?str(id))
????save=pd.Dataframe(data)#格式化數(shù)據(jù)?pandasdatafrane
????save.to_csv(‘data.csv‘?mode=‘a(chǎn)‘?index=False
- 上一篇:jiu0Monkey.yml
- 下一篇:飛機大戰(zhàn)源代碼python
評論
共有 條評論