爬有些网站时会无法获取完整的html(获取的html就不展示了,自己运行,反正获取的html不全)
from requests import get url = "http://bbs.qyai.net/doings" response = get(url).text print(response)
二般情况下,你百度的话会让你模拟登入去,其实是你人品不好罢了
在网站直接按F12,开启F12大法
一般选第一个就行,标头里往下找到Cookie,再进行一顿CV工程
# b就是哪个cookie文件 b = 'remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6ImdvS3FDVTBSMmhxTERVc0I1RFprT3c9PSIsInZhbHVlIjoieTYza3pzUEhzSHZ6bm5nK05EU2VvQTN3anFUQ0RPN2JiTHVkODdNXC8zbHEwcGVMXC9CXC80NEUzeFNpV3krWlVvN1RnY3R3Q28rNWhFU1NmNGp4NitlNGVvRGdMdWxCWU1XS3ZkQXZOWlwvaFVGSUkzcTA3MmIya2owMlhFcVBWRWhPN0lITHhQblFvd1RhZUM3VXdYbkJyako0VWo5d25TVmdUSWg3UUxFbFhSWT0iLCJtYWMiOiJhYWVmNTdmZTY4YmQ3NmUzMzZhODY5YTQ4OTFjY2ZkYzE1OGQ2MzJmODMxODVjMjgxYWRjMGE2MTQ0YjNlZmVhIn0%3D; XSRF-TOKEN=eyJpdiI6IlR1bVlyOFlZNXV0MGh5VzlFMkNMaHc9PSIsInZhbHVlIjoiWFwvSklhbUVtMWVCQ3lDQ0ZoR05WZkNMdjVcL0pNMWQzYStJS2Jaa0p0N1VhMHpBaU1qdzJQYmd2cWZqM050RjI0IiwibWFjIjoiZGYzODU0ZTBiMzU1ZGRiNDA2ZWY0MzA5ZWE1N2I2OTY4Y2E1N2RmZTMyZjc5Njg2NTc3YjRmZTRkNzkzNTExOCJ9; tipask_session=eyJpdiI6ImpLTGdMVVp1UktXcFdpckswb0ZKcmc9PSIsInZhbHVlIjoiVFozaHgyVHpkOXV2Qk5DVExodElPXC91TVlXRmhMNTdqY3NPck9XRWwwblwvNXpCVWdIWnlGOWRlSU1LbThcLzFqMyIsIm1hYyI6IjVmNDA1NGM5MzQ0M2M3NjJiZjQxMzAxYjY0YWRhMGU2MmNmYjE4OTg5ZjA2NDAyMTk5YzY1MmRlYTQ4MjY5NjcifQ%3D%3D' # 但是str没有用,要转成dict类型(聪明的人在看咋转的,更聪明的人晓得百度) cookie ={} for line in b.split(';'): key,value = line.split('=',1) cookie[key] = value response = get(url,cookies=cookie).text print(response)
通过这个cookie就可以获取完整的html了,让你对网站欲罢不能[手动滑稽]
完整代码
from requests import get url = "http://bbs.qyai.net/doings" b = 'remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6ImdvS3FDVTBSMmhxTERVc0I1RFprT3c9PSIsInZhbHVlIjoieTYza3pzUEhzSHZ6bm5nK05EU2VvQTN3anFUQ0RPN2JiTHVkODdNXC8zbHEwcGVMXC9CXC80NEUzeFNpV3krWlVvN1RnY3R3Q28rNWhFU1NmNGp4NitlNGVvRGdMdWxCWU1XS3ZkQXZOWlwvaFVGSUkzcTA3MmIya2owMlhFcVBWRWhPN0lITHhQblFvd1RhZUM3VXdYbkJyako0VWo5d25TVmdUSWg3UUxFbFhSWT0iLCJtYWMiOiJhYWVmNTdmZTY4YmQ3NmUzMzZhODY5YTQ4OTFjY2ZkYzE1OGQ2MzJmODMxODVjMjgxYWRjMGE2MTQ0YjNlZmVhIn0%3D; XSRF-TOKEN=eyJpdiI6IlR1bVlyOFlZNXV0MGh5VzlFMkNMaHc9PSIsInZhbHVlIjoiWFwvSklhbUVtMWVCQ3lDQ0ZoR05WZkNMdjVcL0pNMWQzYStJS2Jaa0p0N1VhMHpBaU1qdzJQYmd2cWZqM050RjI0IiwibWFjIjoiZGYzODU0ZTBiMzU1ZGRiNDA2ZWY0MzA5ZWE1N2I2OTY4Y2E1N2RmZTMyZjc5Njg2NTc3YjRmZTRkNzkzNTExOCJ9; tipask_session=eyJpdiI6ImpLTGdMVVp1UktXcFdpckswb0ZKcmc9PSIsInZhbHVlIjoiVFozaHgyVHpkOXV2Qk5DVExodElPXC91TVlXRmhMNTdqY3NPck9XRWwwblwvNXpCVWdIWnlGOWRlSU1LbThcLzFqMyIsIm1hYyI6IjVmNDA1NGM5MzQ0M2M3NjJiZjQxMzAxYjY0YWRhMGU2MmNmYjE4OTg5ZjA2NDAyMTk5YzY1MmRlYTQ4MjY5NjcifQ%3D%3D' cookie ={} for line in b.split(';'): key,value = line.split('=',1) cookie[key] = value # 关键:cookies参数 response = get(url,cookies=cookie).text print(response)
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!