1、打开cmd窗口,输入jupyter notebook,复制代码打开

python爬取百度网址代码

2、把网址在浏览器打开,建议谷歌或者火狐

python爬取百度网址代码 3、输入一下代码

import requests
from lxml import etree
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'}

 

page = requests.get(url, headers=headers) 
a = etree.HTML(page.text)
for j in range(1,5):
    b = a.xpath('//*[@id="pane-news"]/ul['+str(j)+']/li[1]/a')             
    print(b[0].text)
    for i in range(1,5):
        q = a.xpath('//*[@id="pane-news"]/div/ul/li['+str(i)+']/strong/a')             
        print(q[0].text)

python爬取百度网址代码

相关文章:

  • 2021-08-21
  • 2021-12-06
  • 2022-12-23
  • 2021-06-07
  • 2021-12-07
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2021-11-27
  • 2021-12-01
  • 2021-06-08
  • 2022-12-23
  • 2021-05-03
相关资源
相似解决方案