lihu5841314 ·¢±íÓÚ 2021-5-31 10:14

ΪʲôȡXPATH·¾¶ÀÏÊÇΪ¿ÕÄØ ¸´ÖÆ·¾¶Ò²ÊÇΪ¿Õ(¾­³£ÊÇÓÐʱȡµÃµ½ÓÐʱȡ²»µ½µÄ£©

importre
importrequests
fromlxml importetree


url = "https://www.qidian.com/all"

headers = {
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
    }
sep1=requests.get(url=url,headers=headers).text
tree = etree.HTML(sep1)
detail_url ="https:"+tree.xpath('//div[@class="all-book-list"]//a/@href')
sep2 = requests.get(url=url,headers=headers).text
tree2 = etree.HTML(sep2)
name = tree2.xpath('//*[@id="j-catalogWrap"]/div/div/ul/li')
print(name)

M-Riley ·¢±íÓÚ 2021-5-31 10:32

ÄãÕâ¸öurlÊÇʲô¹í£¿ÌîдÄãÒªÅÀÈ¡µÄÍøÒ³Á´½Ó¾ÍÐÐÁË

lihu5841314 ·¢±íÓÚ 2021-5-31 10:43

M-Riley ·¢±íÓÚ 2021-5-31 10:32
ÄãÕâ¸öurlÊÇʲô¹í£¿ÌîдÄãÒªÅÀÈ¡µÄÍøÒ³Á´½Ó¾ÍÐÐÁË

ÆðµãµÄurl°¡

M-Riley ·¢±íÓÚ 2021-5-31 10:47

lihu5841314 ·¢±íÓÚ 2021-5-31 10:43
ÆðµãµÄurl°¡

ÎÒµÄÒâ˼ÊÇ˵£¬ÄãÖ±½Ó°Ñurl¸ÄΪhttps://www.qidian.com/all¾ÍÐÐÁË£¬ÆäËûµÄÄÇЩ¶¼ÊÇÍøҳǰ¶ËµÄ½á¹¹´úÂë

ÖªÐÄ ·¢±íÓÚ 2021-5-31 10:59

±¾Ìû×îºóÓÉ ÖªÐÄ ÓÚ 2021-5-31 11:12 ±à¼­

//ul[@class="all-img-list cf"]/li/div/a/@href //ͼÊéµØÖ·

//ul[@class="cf"]/li/a/@href   //Õ½ÚÁ´½Ó
//ul[@class="cf"]/li/a/text()//Õ½ڱêÌâ

ÕâÊÇ´úÂëÖÐÐèÒªÓõ½µÄxpath¡£

ÁíÍâÄãµÚ14ÐдúÂëÓÐÎÊÌ⣬ÎÊÌâÔÚurlÉÏ£¬Äã¼ì²éÒ»ÏÂ

lihu5841314 ·¢±íÓÚ 2021-5-31 11:17

ÖªÐÄ ·¢±íÓÚ 2021-5-31 10:59
//ul[@class="all-img-list cf"]/li/div/a/@href //ͼÊéµØÖ·

//ul[@class="cf"]/li/a/@href   //Õ½ÚÁ´ ...

ÕÒ´òÔ­ÒòÁË    url ÓõÄdetail¡ªurl²Å¶Ô

¿É¿ØºË¾Û±ä ·¢±íÓÚ 2021-5-31 14:33

xpath¶àÂ鷳ѽ! Ò»´ó¶Ñ // @@ [ ]£¬cssÑ¡ÔñÆ÷Ö±½Ó . # ¸ã¶¨

Ù©±éÌìÏÂÎÞ¶þÈË ·¢±íÓÚ 2021-5-31 15:33

¿É¿ØºË¾Û±ä ·¢±íÓÚ 2021-5-31 14:33
xpath¶àÂ鷳ѽ! Ò»´ó¶Ñ // @@ [ ]£¬cssÑ¡ÔñÆ÷Ö±½Ó . # ¸ã¶¨

¸÷Óи÷µÄºÃ´¦°É£¬ÒªÊÇÓÐһЩclassÃûËæ»úµÄ£¬»¹µÃÓÃxpath¸¨Öú¶¨Î»
Ò³: [1]
²é¿´ÍêÕû°æ±¾: ΪʲôȡXPATH·¾¶ÀÏÊÇΪ¿ÕÄØ ¸´ÖÆ·¾¶Ò²ÊÇΪ¿Õ(¾­³£ÊÇÓÐʱȡµÃµ½ÓÐʱȡ²»µ½µÄ£©