本帖最后由 luck 于 2018-2-28 09:38 编辑 6 h' H4 P: f6 }0 O) L2 Q2 a( w! N
( E8 v+ Q' D% ^# V刚才我己安装python,然后进 行了以下步骤
8 g ?' M- B/ T1 L附件>运行>CMD 打开了cmd窗口,输入pip install requests ,如下图
$ U \2 Z2 y8 {* {; W
8 B& I ]" B o! z然后呢,怎么办,把下面这段代码放到上面的窗口中吗?1 o% i e; j( J) P" k
import requests P- ?' k; D' }- K
headers = {"user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36" }
/ P3 A- s9 r R% }# p. Qurl = "https://www.aliexpress.com/category/5090301/mobile-phones.html"
, y9 S3 Q. G" L4 Q0 S6 J Iresponse = requests.get(url, headers=headers), M' t% C8 i; M v- B
html = etree.HTML(response.content)" K- P9 k! C" H" r- S2 o1 n7 S
print(response.text)7 M3 J3 r6 D- e: T
btlist= html.xpath(".//h3[@class='icon-hotproduct']/a/@title")
$ K& w/ y, V4 |+ v- e) v h+ _for title in btlist:5 H) I+ p! ]' p* ]) q
print(title) 这是输入后的结果 . o5 d4 G7 Q! f9 v% G3 N
% X' p1 u# x" }& q" |怎么办?! p: E Y2 t" q
原谅我太笨了,谢谢!
# f) [+ C Y6 e& ~' k U
5 g% J8 W6 p7 j% ^( W6 x0 y4 C% w8 w% F8 L n8 F
|