os库
os库:
print(os.listdir())
print(os.getcwd())
print(os.path.exists('./aaa'))
if not os.path.exists('./bbb'):
os.mkdir('./bbb')
print(os.path.dirname(__file__))
file_path = os.path.join(os.path.dirname(__file__),'aaa','6test.jpg')
print(file_path)
爬虫
url='网站链接/'
headers = {
'User-Agent':’’ (在检查中的Network中的Doc中,点击文件后移至user-agent复制)
}
resp=requests.get(url, headers=headers)
print(resp.status_code)
if resp.status_code==200:
html=resp.text
print(html)
dom = etree.HTML(html)
xpath_pattern='(xpath入口:ctrl+f触发)'
titles=dom.xpath(xpath_pattern)
print('titles',titles)