网站实战

网站实战

注意以上两图红色部分以及运行结果的区别,附源代码如下:

import requests
from lxml import etree
url = 'http://weekend.ctrip.com/around/'
response = requests.get(url)
html = response.content.decode()
html = etree.HTML(html)
divs = html.xpath('//div[@class="wc_link_title"]')
for div in divs:
    title = div.xpath('a/text()')[0]
    url_l = 'http://weekend.ctrip.com' + div.xpath('a/@href')[0]
    response = requests.get(url_l)
    html = response.content.decode()
    html = etree.HTML(html)
    divs = html.xpath('//div[@class="product_m"]')
    for div in divs:
         title = div.xpath('h2/a/text()')[0]
         href = div.xpath('h2/a/@href')[0]
         print(title, href)


相关文章:

  • 2021-05-31
  • 2021-08-26
  • 2022-12-23
  • 2021-04-05
  • 2021-09-18
  • 2021-11-30
  • 2021-12-15
  • 2021-09-05
猜你喜欢
  • 2021-08-04
  • 2022-03-05
  • 2021-07-08
  • 2023-03-31
  • 2021-11-17
  • 2021-09-20
  • 2021-11-03
相关资源
相似解决方案