chenxi188
import requests
from pyquery import PyQuery as pq

url=\'https://www.zhihu.com/explore\'
headers={
    \'User-Agent\':\'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36\'
    }
html=requests.get(url,headers=headers).text
doc=pq(html)
items=doc(\'.explore-tab .feed-item \').items()
#print(items)

for item in items:
    question = item.find(\'h2\').text()
    author = item.find(\'.author-link-line\').text()
    answer = pq(item.find(\'.content\').html()).text()
    file = open(\'explore.txt\', \'a\', encoding=\'utf-8\')
    file.write(\'\n\'.join([question, author, answer]))
    file.write(\'\n\' + \'=\' * 50 + \'\n\')
    file.close()

 

分类:

技术点:

相关文章:

  • 2021-06-16
  • 2021-11-27
  • 2022-02-09
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-07
  • 2021-10-20
  • 2021-06-23
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
相关资源
相似解决方案