|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import requests |
| 3 | +from bs4 import BeautifulSoup |
| 4 | +import time |
| 5 | +import json |
| 6 | + |
| 7 | +headers = { |
| 8 | + 'cookie': '自己 cookie', |
| 9 | + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36', |
| 10 | +} |
| 11 | + |
| 12 | +def all_appraisal(): |
| 13 | + appraisal = {} |
| 14 | + url = "https://club.jd.com/myJdcomments/myJdcomment.action?sort=0" |
| 15 | + req = requests.get(url, headers=headers) |
| 16 | + soup = BeautifulSoup(req.text, "html.parser") |
| 17 | + url = soup.find('ul', class_='tab-trigger'); |
| 18 | + for li in url.find_all('li'): |
| 19 | + contents = li.a.text |
| 20 | + b = li.b |
| 21 | + if b != None: |
| 22 | + appraisal[contents] = int(b.text) |
| 23 | + return appraisal |
| 24 | + |
| 25 | + |
| 26 | +def be_evaluated(appraisal): |
| 27 | + for i in range((appraisal['待评价订单'] // 20) + 1): |
| 28 | + url = 'https://club.jd.com/myJdcomments/myJdcomment.action?sort=0&page={}'.format(i + 1) |
| 29 | + req = requests.get(url, headers=headers) |
| 30 | + soup = BeautifulSoup(req.text, "html.parser") |
| 31 | + table = soup.find('table', class_ = 'td-void order-tb'); |
| 32 | + tbodys = table.find_all('tbody') |
| 33 | + for order in tbodys: |
| 34 | + oid = order.find('span', class_="number").a.text |
| 35 | + product = order.find('div', class_='p-name').a |
| 36 | + pname = product.text |
| 37 | + pid=product['href'].replace('//item.jd.com/', '').replace('.html', '') |
| 38 | + content = pname + ',东西质量非常好,与卖家描述的完全一致,非常满意,真的很喜欢,完全超出期望值,发货速度非常快,包装非常仔细、严实,物流公司服务态度很好,运送速度很快,很满意的一次购物' |
| 39 | + |
| 40 | + |
| 41 | + saveProductComment_url = "https://club.jd.com/myJdcomments/saveProductComment.action" |
| 42 | + saveProductComment_data = { |
| 43 | + 'orderId': oid, |
| 44 | + 'productId': pid, |
| 45 | + 'score': '5', |
| 46 | + 'content': bytes(content, encoding="gbk"), |
| 47 | + 'saveStatus': '1', |
| 48 | + 'anonymousFlag': '1' |
| 49 | + } |
| 50 | + save = requests.post(saveProductComment_url, headers=headers, data=saveProductComment_data) |
| 51 | + time.sleep(5) |
| 52 | + |
| 53 | +def be_shown_img(): |
| 54 | + url = 'https://club.jd.com/myJdcomments/myJdcomment.action?sort=1' |
| 55 | + req = requests.get(url, headers=headers) |
| 56 | + soup = BeautifulSoup(req.text, "html.parser") |
| 57 | + pro_info = soup.find_all('div', class_ = 'pro-info'); |
| 58 | + for plist in pro_info: |
| 59 | + oid = plist['oid'] |
| 60 | + pid = plist['pid'] |
| 61 | + |
| 62 | + img_url = 'https://club.jd.com/discussion/getProductPageImageCommentList.action?productId={}'.format(pid) |
| 63 | + img_req = requests.get(img_url, headers=headers) |
| 64 | + text = img_req.text |
| 65 | + print(img_url) |
| 66 | + |
| 67 | + result = json.loads(text) |
| 68 | + imgurl = result["imgComments"]["imgList"][0]["imageUrl"] |
| 69 | + |
| 70 | + |
| 71 | + saveUrl = 'https://club.jd.com/myJdcomments/saveShowOrder.action' |
| 72 | + img_data = { |
| 73 | + 'orderId': oid, |
| 74 | + 'productId': pid, |
| 75 | + 'imgs': imgurl, |
| 76 | + 'saveStatus': 3 |
| 77 | + } |
| 78 | + print(img_data) |
| 79 | + header = headers |
| 80 | + header['Referer'] = 'https://club.jd.com/myJdcomments/myJdcomment.action?sort=1' |
| 81 | + header['Origin'] = 'https://club.jd.com' |
| 82 | + header['Content-Type'] = 'application/x-www-form-urlencoded' |
| 83 | + requests.post(saveUrl, data=img_data, headers=header) |
| 84 | + time.sleep(5) |
| 85 | + |
| 86 | +def review(): |
| 87 | + |
| 88 | + appraisal = all_appraisal() |
| 89 | + saveUrl = 'https://club.jd.com/afterComments/saveAfterCommentAndShowOrder.action' |
| 90 | + for i in range((appraisal['待评价订单'] // 20) + 1): |
| 91 | + |
| 92 | + url = 'https://club.jd.com/myJdcomments/myJdcomment.action?sort=3&page={}'.format(i+1) |
| 93 | + req = requests.get(url, headers=headers) |
| 94 | + soup = BeautifulSoup(req.text, "html.parser") |
| 95 | + operates = soup.find_all('div', class_='operate') |
| 96 | + for o in operates: |
| 97 | + href = o.a['href'] |
| 98 | + infos = href.replace('http://club.jd.com/afterComments/productPublish.action?sku=','').split('&orderId='); |
| 99 | + pid = infos[0] |
| 100 | + oid = infos[1] |
| 101 | + |
| 102 | + data = { |
| 103 | + 'orderId': oid, |
| 104 | + 'productId': pid, |
| 105 | + 'content': bytes('宝贝和想象中差不多所以好评啦,对比了很多家才选择了这款,还是不错的,很NICE!真的', encoding='gbk'), |
| 106 | + 'imgs': '', |
| 107 | + 'anonymousFlag': 1, |
| 108 | + 'score': 5 |
| 109 | + } |
| 110 | + |
| 111 | + requests.post(saveUrl, headers=headers, data=data) |
| 112 | + |
| 113 | + time.sleep(5) |
| 114 | + |
| 115 | +def service_rating(): |
| 116 | + appraisal = all_appraisal() |
| 117 | + saveUrl = 'https://club.jd.com/myJdcomments/insertRestSurvey.action?voteid=145&ruleid={}' |
| 118 | + for i in range((appraisal['服务评价'] // 20) + 1): |
| 119 | + url = "https://club.jd.com/myJdcomments/myJdcomment.action?sort=4&page={}".format(i + 1) |
| 120 | + req = requests.get(url, headers=headers) |
| 121 | + soup = BeautifulSoup(req.text, "html.parser") |
| 122 | + trs = soup.find_all('tr', class_='tr-th'); |
| 123 | + for tr in trs: |
| 124 | + oid = tr.find('span', class_='number').a.text |
| 125 | + saveUrl = saveUrl.format(oid) |
| 126 | + data = { |
| 127 | + 'oid': oid, |
| 128 | + 'gid': 69, |
| 129 | + 'sid': 549656, |
| 130 | + 'stid': 0, |
| 131 | + 'tags': '', |
| 132 | + 'ro1827': '1827A1', |
| 133 | + 'ro1828': '1828A1', |
| 134 | + 'ro1829': '1829A1', |
| 135 | + } |
| 136 | + requests.post(saveUrl, headers=headers, data=data) |
| 137 | + print('订单号:' + oid + '服务评价完成') |
| 138 | + time.sleep(5) |
| 139 | + |
| 140 | +if __name__ == '__main__': |
| 141 | + # appraisal = all_appraisal() |
| 142 | + service_rating() |
| 143 | + |
0 commit comments